In the late 18th century, Barbary pirates terrorized Mediterranean shipping from their bases in Algiers, Tunis, Tripoli and Morocco. The local rulers both abetted, and profited from, their activities. The pirates demanded large ransoms for ships and crew they captured, then tribute from the affected governments to avoid further attacks. In 1800, such ransom and tribute comprised over 10 per cent of total US government revenues, and the incoming President Thomas Jefferson vowed to stamp out the piracy, refusing to pay the annual tribute. On hearing this, Tripoli declared war on the USA. Between 1803–05, the US navy, allied to Sweden, engaged in several inconclusive encounters, bombarding pirate ports before capturing Derna and securing the release of their sailor hostages. When piracy resumed during the Anglo-Amercan War of 1812, the US mounted a fresh expedition, forcing peace on Algiers in 1815. The British bombardment of Algiers (1816) effectively ended the epidemic of piracy.
— OR —