The First Barbary War (1801–1805, also known as the Barbary Coast War or the Tripolitan War) was one of two wars fought between the United States of America and the North African empire of Morocco and city-states of Algiers, Tunis, and Tripoli, known collectively as the Barbary States.



Since the 17th century, Algiers, Tunis, and Tripoli, although nominally governed by the Ottoman Empire, had been largely independent kleptocracies, run by piratical military strongmen and financed by plunder, tribute, and ransom. The monarchy of Morocco, which, by the time of the Barbary Wars, dated back more than one thousand years, was equally well-known for supporting piracy. The nations of Britain and France had come to uneasy ententes with the pirates; a combination of military might, diplomacy, and under-the-counter payments had kept ships flying the Union Jack or fleur-de-lys more or less safe from attack. As British colonists before 1776, American merchant vessels had enjoyed the protection of the Royal Navy. During the American Revolution, American ships came under the aegis of France due to a 1778 Treaty of Alliance between the two countries. By 1783, however, with the end of the Revolution, America became solely responsible for the safety of its own commerce and citizens. Without the means or the authority to field a naval force necessary to protect their ships in the Mediterranean, the nascent U.S. government took a pragmatic, but ultimately self-destructive route. In 1784, the United States Congress allocated money for payment of tribute to the pirates. Use for the money came in 1785, when the dey of Algiers took two American ships hostage and demanded $60,000 in ransom for their crews. The U.S. paid Algiers the ransom, and continued to pay up to $1 million per year over the next 15 years for the safe passage of American ships or the return of American hostages. Payments in ransom and tribute to the prirateer states amounted to 20 percent of United States government annual revenues in 1800.

On Jefferson's inauguration as president in 1801, Yussif Karamanli, the pasha of Tripoli demanded $225,000 from the new administration. Putting his long-held beliefs into practice, Jefferson refused the demand. Consequently, in May of 1801, the pasha declared war on the United States, not through any formal written documents, but by cutting down the flagstaff in front of the U.S. Consulate. Morocco, Algiers, and Tunis soon followed their ally. In response, Jefferson sent a group of frigates to defend American interests in the Mediterranean, and informed Congress. Although Congress never voted on a formal declaration of war, they did authorize the President to instruct the commanders of armed vessels of the United States to seize all vessels and goods of the Bay of Tripoli "and also to cause to be done all such other acts of precaution or hostility as the state of war will justify." Algiers and Tunis backed down almost immediately on the show of force by the Americans, but Tripoli and Morocco remained committed. The American navy went unchallenged in the sea, and as the question remained undecided. Jefferson pressed the issue the following year, with an increase in military force and deployment of many of the navy's best ships to the region throughout 1802. In October of 1803, the fleet of Tripoli was able to capture the USS Philadelphia intact after the frigate ran aground while patrolling Tripoli harbor. Efforts by the Americans to float the ship while under fire from shore batteries and Tripolitanian naval units were unsuccessful. The ship, its captain, William Bainbridge, and all officers and crew were taken ashore and held as hostages. On February 16, 1804, a small contingent of sailors in a disguised Intrepid and led by Lieutenant Stephen Decatur, Jr., were able to invade the harbor of Tripoli and burn the Philadelphia, denying her use to the enemy. Decatur's bravery in action made him a hero to Americans back home. Preble attacked Tripoli outright on July 14, 1804 in a series of inconclusive battles. The turning point in the war came with the Battle of Derne, after a remarkably daring overland attack on the Tripolitan city of Derna by a combined force of American marines and Arab, Greek and Berber mercenaries under the command of ex-consul William Eaton and Lieutenant Presley O'Bannon. This action, memorialized in the Marine Hymn—"to the shores of Tripoli"—gave the American forces a significant advantage. Wearied of the blockade and raids, and now under threat of a continued advance on Tripoli proper and a scheme to set up his brother Hamet Karamanli as ruler, Karamanli signed a treaty ending hostilities on June 10, 1805. Although the Senate did not approve the treaty until the following year, this effectively ended the First Barbary War. Although it seems that the United States paid a further tribute to the Bashaw of Tripoli in return for captured sailors, the First Barbary War is generally considered to have been beneficial to the United States. The more immediate problem of Barbary piracy, however, was not fully settled. By 1807, Algiers had gone back to taking American ships and seamen hostage. Distracted by the preludes to the War of 1812, the Americans were unable to respond to the provocation until 1815, with the Second Barbary War. 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 the 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 their crews 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 the prisoners.



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. Algiers and Tunis became colonies of France in 1830 and 1881 respectively, while Tripoli returned to the control of the Ottoman Empire in 1835 and became a colony of Italy in 1911. Europeans remained in control of the government there until the mid-twentieth century.