"From the halls of Montezuma,
To the shores of Tripoli;"
The second line in the first stanza of the Marine Corps hymn refers to the the port of Tripoli in North Africa and the role the U.S. Marines played in the Barbary Wars, a conflict where a reborn U.S. Navy fought against the Barbary Pirates. The Pirates of the Barbary Coast for hundreds of years preyed on the merchant shipping in the Mediterranean demanding ransom and tribute from the nations of Europe. Once the 13 American colonies became independent of Great Britain, the American merchant fleet was also subject to attack from the North African corsairs.
Upon the conclusion of hostilities with Britain, it was felt that there was no longer a need for an American navy. The fighting men of the Navy were cashiered and their ships were sold or given away. But as a new nation with a long coastline and a large merchant marine the United States found itself in a very vulnerable position. Americas first threat was from French privateers, which led to an undeclared war against France (1798-1800). The U.S. then had to deal with the Barbary pirates.
The large American merchant fleet sailing in the Mediterranean was a tempting target for the pirates. American sailing ships were captured and the men on board were held for ransom and kept in dungeons, subject to horrible living conditions. In response to these events and others in 1794 the U.S. had passed an act authorizing a new American Navy. Six large heavy frigates, including the U.S.S. Constitution, were ordered to be built and the American Navy and its Corps of Marines was reborn.