After its victory in the First Barbary War (1801 - 1805), the attention of the United States had been diverted to its worsening relationship with France and United Kingdom, culminating in the War of 1812. The unchastened Barbary pirate states took this opportunity to return to their practice of attacking American merchant vessels in the Mediterranean Sea and holding the crew and officers for ransom. Unable to devote military resources and political will to the situation, the United States quietly recommenced paying ransom for return of prisoners.
The expulsion of American vessels from the Mediterranean during the War of 1812 by the British navy further emboldened the brigandine nations. The Dey of Algiers expelled the US consul general Tobias Lear and declared war on the United States for failing to pay its required tribute. Since there were no American vessels in the region at this time, the challenge went unheeded.
The Napoleonic wars of the early nineteenth century diverted the attention of the maritime powers from suppressing what they derogatorily called piracy. But when peace was restored to Europe in 1815, Algiers found itself at war with Spain, the Netherlands, Prussia, Denmark, Russia, and Naples.
At the conclusion of the War of 1812, however, America could once again turn its sights on North Africa. On March 3, 1815 the US Congress authorized deployment of naval power against Algiers, and a force of ten ships was dispatched under the command of Commodores Stephen Decatur, Jr and William Bainbridge -- both heroes of the first war.
Decatur and Bainbridge used the pirates' tactics against them. Taking hundreds of prisoners in an attack on Algiers, Decatur bargained for a treaty releasing the United States from any tribute obligations in perpetuity, as well as $10,000 in reparations for damages to the US. By June 30, 1815 the treaty was signed and the threat of Barbary pirates to American vessels was at an end.
No sooner had Decatur set off for Tunis to enforce a similar agreement than the dey repudiated the treaty. The next year, an Anglo-Dutch fleet, commanded by British admiral Viscount Exmouth, delivered a punishing, nine-hour bombardment of Algiers. The attack immobilized many of the dey's corsairs and obtained from him a second treaty that reaffirmed the conditions imposed by Decatur. In addition, the dey agreed to end the practice of enslaving Christians.