The Barbary pirates, who had been marauding off the coast of Africa for centuries, encountered a new enemy in the early 19th century: the young United States Navy. The North African pirates had been a menace for so long that by the late 1700s most nations paid tribute to ensure that merchant shipping could proceed without being violently attacked. In the early years of the 19th century, the United States, at the direction of President Thomas Jefferson, decided to halt the payment of tribute. A war between the small and scrappy American Navy and the Barbary pirates ensued. A decade later, a second war settled the issue of American ships being attacked by pirates. The issue of piracy off the African coast seem to fade into the pages of history for two centuries until resurfacing in recent years when Somali pirates clashed with the U.S. Navy.

Background of the Barbary Pirates FPG/ Taxi// Getty Images The Barbary pirates operated off the coast of North Africa as far back as the time of the Crusades. According to legend, the Barbary pirates sailed as far as Iceland, attacking ports, seizing captives and enslaving them, and plundering merchant ships. As most seafaring nations found it easier, and cheaper, to bribe the pirates rather than fight them in a war, a tradition developed of paying tribute for passage through the Mediterranean. European nations often worked out treaties with the Barbary pirates. By the early 19th century the pirates were essentially sponsored by the Arab rulers of Morocco, Algiers, Tunis, and Tripoli.

American Ships Were Protected Before Independence Before the United States achieved independence from Britain, American merchants ships were protected on the high seas by Britain's Royal Navy. But when the young nation was established its shipping could no longer count on British warships keeping it safe. In March 1786, two future presidents met with an ambassador from the pirate nations of North Africa. Thomas Jefferson, who was the U.S. ambassador in France, and John Adams, the ambassador to Britain, met with the ambassador from Tripoli in London. They asked why American merchant ships were being attacked without provocation. The ambassador explained that Muslim pirates considered Americans to be infidels and they believed they simply had the right to plunder American ships.

America Paid Tribute While Preparing for War Preparation for WAR to Defend Commerce. courtesy New York Public Library Digital Collections The U.S. government adopted a policy of essentially paying bribes, politely known as tribute, to the pirates. Jefferson objected to the policy of paying tribute in the 1790s. Having been involved in negotiations to free Americans held by North African pirates, he believed paying tribute only invited more problems. The young U.S. Navy was preparing to deal with the problem by building a few ships destined to fight the pirates off Africa. Work on the frigate Philadelphia was depicted in a painting titled "Preparation for WAR to Defend Commerce." The Philadelphia was launched in 1800 and saw service in the Caribbean before becoming involved in a pivotal incident in the first war against the Barbary pirates.

1801-1805: The First Barbary War Capture of Algerine Corsair. courtesy New York Public Library Digital Collections When Thomas Jefferson became president, he refused to pay any more tribute to the Barbary pirates. And in May 1801, two months after he was inaugurated, the pasha of Tripoli declared war on the United States. The US Congress never issued an official declaration of war in response, but Jefferson dispatched a naval squadron to the coast of North Africa to deal with the pirates. The American Navy's show of force quickly calmed the situation. Some pirate ships were captured, and the Americans established successful blockades. But the tide turned against the United States when the frigate Philadelphia ran aground in the harbor of Tripoli (in present day Libya) and the captain and crew were captured.

Stephen Decatur Became an American Naval Hero Stephen Decatur Boarding the Philadelphia. courtesy New York Public Library Digital Collection The capture of the Philadelphia was a victory for the pirates, but the triumph was short-lived. In February 1804, Lieutenant Stephen Decatur of the U.S. Navy, sailing a captured ship, managed to sail into the harbor at Tripoli and recapture the Philadelphia. He burned the ship so it couldn't be used by the pirates. The daring action became a naval legend. Stephen Decatur became a national hero in the United States and he was promoted to captain. The captain of the Philadelphia, who was eventually released, was William Bainbridge. He later went on to greatness in the U.S. Navy. Coincidentally, one of the U.S. Navy ships involved in action against pirates off Africa in April 2009 was the USS Bainbridge, which was named in his honor.

To the Shores of Tripoli In April 1805 the U.S. Navy, with U.S. Marines, launched an operation against the port of Tripoli. The objective was to install a new ruler. The detachment of Marines, under the command of Lieutenant Presley O'Bannon, led a frontal assault on a harbor fort at the Battle of Derna. O'Bannon and his small force captured the fort. Marking the first American victory on foreign soil, O'Bannon raised an American flag over the fortress. The mention of the "shores of Tripoli" in the "Marine's Hymn" refers to this triumph. A new pasha was installed in Tripoli, and he presented O'Bannon with a curved "Mameluke" sword, which is named for North African warriors. To this day Marine dress swords replicate the sword given to O'Bannon.

A Treaty Ended the First Barbary War After the American victory at Tripoli, a treaty was arranged which, while not entirely satisfactory for the United States, effectively ended the First Barbary War. One problem which delayed ratification of the treaty by the U.S. Senate was that ransom had to be paid to free some American prisoners. But the treaty was eventually signed, and when Jefferson reported to the Congress in 1806, in the written equivalent of the president's State of the Union Address, he said the Barbary States would now respect American commerce. The issue of piracy off Africa faded into the background for about a decade. Problems with Britain interfering with American commerce took precedence, and eventually led to the War of 1812.

1815: The Second Barbary War Stephen Decatur Meets the Dey of Algiers. courtesy New York Public Library Digital Collections During the War of 1812 American merchant ships were kept out of the Mediterranean by Britain's Royal Navy. But problems arose again with the war's end in 1815. Feeling that the Americans had been seriously weakened, a leader with the title of the Dey of Algiers declared war on the United States. The U.S. Navy responded with a fleet of ten ships, which were commanded by Stephen Decatur and William Bainbridge, both veterans of the earlier Barbary war. By July 1815 Decatur's ships had captured several Algerian ships and forced the Dey of Algiers to commit to a treaty. Pirate attacks on American merchant ships were effectively ended at that point.