Alrighty then, let's see...
So, from the late 16th to early 19th century, the Ottoman vassals of Algiers, Tunis, and Tripoli, more or less had the run of the southern Mediterranean, seizing ships from various European powers for ransom and more or less doing as they pleased.
For most continental empires, this was an annoyance, but not one worth the effort to deal with. They would pay the Barbary pirates their demanded tributes, and their ships would go unmolested (except when they didn't.)
However, in 1783, something changed. The United States became formally independent from the British Empire, meaning that their shipping no longer fell under the protection of English tributes. As quickly as October of 1784, American ships were being harassed by pirates.
However, for some time, this state of affairs would continue, with the US paying tribute to the Ottoman vassals and biting their tongue every time the pirates attacked anyway, knowing the fledgling nation had no naval capacity with which to retaliate. The United States, after all, was still very young, and financing the construction of a professional navy was simply outside of their capability.
While 1794 would bring about the recommissioning of the navy, and 1800 the official commissioning of six frigates to "be officered and manned as the President of the United States may direct", it would also see a tribute of approximately $1,440,000 (more than 30 million dollars in today's dollars) given over to the Barbary states for the release of American sailors taken as slaves.
However, with the 1800 presidential election would come a turn in policy. It was custom for the Barbary pirates to demand an extra tribute from every new government that took charge of a nation with whom they had a treaty, and that is exactly what Yusuf Karamanli, the Pasha of Tripoli at the time, demanded from the US when President Thomas Jefferson took office.
However, unlike the previous administrations, Jefferson refused to give any tribute, leading to the Tripolitan government declaring war on the United States of America on the 10th of May, 1801. This gave Jefferson all the Casus Belli he needed to send the Navy and their Marine accompaniment in to deal with the Barbary Pirates for good.
So, now that the background is established, let's fast forward to 1804, where the Marines actually become relevant to this story. After a fairly successful naval blockade, and several key victories, In October 1803, the Tripolitan fleet managed to seize the USS Philadelphia, after a hidden reef ran the ship aground. All hands were taken as hostages, and the ship itself was converted into a gun battery to defend the harbor. As you can imagine, this was a massive embarrassment to the United States, and so it was considered an objective of extreme importance to either recover the ship, or deny the enemy its use.
On 16 February, 1804, USMC captain Stephen Decatur would lead a small force, operating from a stolen Tripolitan vessel, to storm the captured Philadelphia and destroy it, signaling to all that the Marines were here, and they did not intend to fuck around.
However, the true showing of the Marines would come at the Battle of Derna, where First Lieutenant Presley O'Bannon would lead a handful of marines and more than five hundred mercenaries on a 700 kilometer march from Alexandria to Derna, where they would then storm and capture the city, earning the United States Marines infamy from their allies and enemies both as uniquely fearsome combatants. To this day, this battle is remembered in the Marine's Hymn, celebrating their victories "From the halls of Montezuma to the shores of Tripoli."
This victory at Derna finally gave US negotiators the leverage they needed to broker a treaty with Pasha Karamanli, securing the cessation of hostilities and the return of all United States Personnel. This marked the first time that US troops performed a major operation outside of their own territory, and proved that Americans could play on the same field as other powers, cementing their reputation as a military power in their own right.
For his bravery and ferocity in the heat of battle, 1LT O'Bannon was gifted a sword by Prince Hamet Karamanli, exiled brother of the Tripolitan Pasha. This sword would go on to be the sterling example of the "Mameluke sword", and blades made in its likeness are carried by USMC officers to this very day.