The Barbary War was actually two wars. One fought from 1801 to 1805, the other during 1815.
The Second Barbary War was much more successful. After tangling with the Royal Navy in the War of 1812, Barbary pirates weren’t hard to handle.
BTW, does everyone know that this war was the first war for the Marines. In fact, they are called leathernecks because they wore leather collars to keep the Muslim pukes from cutting their heads off...