In December 1777, the Moroccan Sultan Mohammed III included the United States in a list of countries to which Morocco's ports were open. Morocco thus became the first country whose head of state publicly recognized the newly-independent United States. Relations were formalized with the Moroccan–American Treaty of Friendship, which was negotiated by Thomas Barclay in Marrakesh and signed by American diplomats in Europe, Thomas Jefferson, and John Adams with Sultan Mohammed III in 1786. Muhammad III, or Sidi Muhammad bin Abdallah, came to power in 1757 and ruled until his death in 1790. Prior to his reign, Morocco had experienced 30 years of internecine battles, instability and turmoil. Sidi Muhammad transformed politics, the economy and society by prioritizing development of international trade and restoring power to the sultanate, which improved Morocco's standing internationally. Central to his pursuit of international trade was the negotiation of agreements with foreign commercial powers. He began seeking one with the United States before the war with Great Britain had ended in 1783, and he welcomed Thomas Barclay's arrival to negotiate in 1786. The treaty signed by Barclay and the sultan and 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 234 years, which makes it the longest unbroken treaty relationship in United States history. See also List of treaties Morocco–United States relations Moorish sovereign citizens References External links English text of the treaty from Yale's Lillian Goldman Law Library History of The Moroccan–American Treaty of Friendship and Moroccan–American Relations Historical Background Morocco-US relations, Embassy of the Kingdom of Morocco Moroccan–U.S. Relations, 1750–1912 1786 in the United States 1786 treaties Barbary Wars American Morocco–United States relations Treaties of Morocco Treaties of the United States 1786 in Africa Ordinances of the Continental Congress