Morocco was the first nation to recognise the fledgling United States as an independent nation in 1777. In the beginning of the American Revolution, American merchant ships in the Atlantic Ocean were subject to attack by the Barbary pirates. On 20 December 1777, Morocco's Sultan Mohammed III declared that American merchant ships would be under the protection of the sultanate and could thus enjoy safe passage. The Moroccan–American Treaty of Friendship (also known as the Treaty of Marrakesh) was negotiated by Thomas Barclay in Marrakesh, and signed by American diplomats in Europe, Thomas Jefferson, John Adams with Sultan Muhammad III in 1786.

The treaty signed by Barclay and the sultan, then by Jefferson and Adams, was ratified by the Confederation Congress in July 1787. It was reaffirmed by the sultan in 1803 when the USS Constitution, Nautilus, New York, and Adams engaged in gunboat diplomacy as part of the First Barbary War. (At the time, independent corsairs and pirates were using Morocco's ports as safe harbors between raids on American and European shipping.) The treaty has withstood transatlantic stresses and strains for more than 232 years, making it the longest unbroken treaty relationship in United States history.

More Info: en.wikipedia.org