Read Kilmead’s book on the Barbary wars. Britain was neutral and Gibraltar is where both the US and Muslim ships were anchored. Muslims knew that once they left Gibralter all bets were off. The war of 1812 gave the muslims the opportunity to attack us (again) after they surrendered and agreed to stop that crap.
You mean wikipedia is not good enough? /s ;)
Interesting, the brits then used the muslims to attack America, much like they do nowadays with the islamic speech pogroms to control populations.