In December 1777, the Moroccan Sultan Muhammad III included the United States of America 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 new United States. Relations were formalized with the Moroccan–American Treaty of Friendship negotiated by Thomas Barclay, and signed by Thomas Jefferson, John Adams and Muhammad III in 1786.
Muhammad III, or Sidi Muhammad ibn 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. During the 33 years Sidi Muhammad ruled he transformed the politics, the economy and the society, putting development of international trade high on his agenda and restoring power to the sultanate. This served to quickly bring respect to Morocco on the international scene. Central to his pursuit of international trade was the negotiation of agreements with foreign commercial powers. He actively began seeking one with the United States well before the war with Great Britain was settled in 1783, finally got America's attention in 1784, and warmly welcomed Thomas Barclay's arrival to negotiate 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 has withstood transatlantic stresses and strains for more than 220 years, making it the longest unbroken treaty relationship in United States history.