The port of Tripoli, in modern day Libya, was an important center for the Barbary Pirates in the 17th, 18th, and 19th centuries. Tripoli, however, is best known as the main battleground of the first Barbary War.
In 1801, the pasha (ruler) of Tripoli demanded an increase in the tribute that the United States paid every year to ensure the safe passage of their trade ships in the Mediterranean Sea. Thomas Jefferson, who was president at the time, had always hated the idea of paying the pasha. Jefferson refused the demand and dispatched a U.S. Naval fleet to blockade Tripoli. Meanwhile, the pasha of Tripoli declared war on the United States, as did Tunis and Algiers. The first battle took place in Tripoli Harbor on August 1, 1801. In the battle, the USS Enterprise captured the pirate ship Tripoli. In 1802, Jefferson sent a more formidable fleet to the region that consisted of many of the Navy's best ships. These ships turned the tables on the Barbary Pirates as their crews conducted attacks and raids on the Barbary fleets docked in Tripoli and other African ports.
In 1803, the Americans suffered their first defeat in the Barbary War when the frigate USS Philadelphia ran ashore as it was patrolling Tripoli Harbor. The entire crew was captured and held hostage. About five months later, Lieutenant Stephen Decatur and his men led a daring rescue attempt into Tripoli Harbor. Decatur led the USS Intrepid, which was disguised as an Ottoman vessel into Tripoli Harbor, where he was able to burn the USS Philadelphia and deny its use to the enemy. The crew was later ransomed for a sum of about $60,000.
In 1804, Edward Preble and several detachments attacked the city of Tripoli itself. In one of the battles, Captain Richard Somers and his crew packed their ship, the USS Intrepid, with explosives for the purposes of destroying itself and the enemy fleet. Unfortunately, it was attacked before it could reach the enemy fleet and Somers and his crew were killed.
In April and May of 1805, the United States finally made progress in its war against the Barbary Pirates. U.S. forces and 500 Arab and Greek mercenaries led by General William Eaton marched 500 miles from Alexandria, Egypt to Derne (near Tripoli) for the purposes of occupying the city. On the coast, were Captain Isaac Hull and three naval vessels to provide bombardment support. The combined naval and land attack overwhelmed the city's defenses. Within a couple of hours the entire city was in American hands. It was the first time America had waged a land battle on foreign soil. This battle inspired the portion of the Marine Hymn that reads "To the shores of Tripoli".