Morocco is the first country to recognize the U.S.
On December 20, 1777, the Kingdom of Morocco became the first country in the world to recognize United States independence, only a year and a half after the U.S. Declaration of Independence was issued. The War of Independence was still in progress, and the result was still far from certain.
In the 1780s, after independence had been secured, Moroccan pirates threatened American shipping in the Mediterranean. Thomas Barclay, the American consul in France, arrived in Morocco in 1786. There he negotiated the Moroccan-American Treaty of Friendship, which was signed later that year in Europe by John Adams and Thomas Jefferson.Under Sultan Mohammed III, Morocco became at once the first Arab state, the first African state, and the first Muslim state to sign a treaty with the United States. Congress ratified the Treaty of Peace and Friendship between the two nations in 1787. Renegotiated in 1836, the treaty is still in force, constituting the longest unbroken treaty relationship in U.S. history.
Wiki: Barbary corsairs and crews from the North African Ottoman provinces of Algiers, Tunis, Tripoli, and the independent Sultanate of Morocco under the Alaouite dynasty (the Barbary Coast) were the scourge of the Mediterranean. ...between 1 and 1.25 million Europeans were captured by Barbary pirates and sold as slaves between the 16th and 19th centuries.
On 11 October 1784, Moroccan pirates seized the brigantine Betsey. The Spanish government negotiated the freedom of the captured ship and crew; however, Spain offered advice to the United States on how to deal with the Barbary States. The advice was to offer tribute to prevent further attacks against merchant ships. The U.S. Minister to France, Thomas Jefferson, decided to send envoys to Morocco and Algeria to try to purchase treaties and the freedom of the captured sailors held by Algeria. Morocco was the first Barbary Coast State to sign a treaty with the U.S., on 23 June 1786. This treaty formally ended all Moroccan piracy against American shipping interests. Specifically, article six of the treaty states that if any Americans captured by Moroccans or other Barbary Coast States docked at a Moroccan city, they would be set free and come under the protection of the Moroccan State.