Morocco was the first country to recognize the United States as an independent nation.
Sultan Mohammed III of Morocco opened Moroccan ports to American ships in 1777, making Morocco the first country to recognize the United States after the Declaration of Independence. The gesture was important because the American republic was still fighting Britain and had not yet secured broad diplomatic recognition.
The two countries later formalized their relationship through the Moroccan-American Treaty of Friendship. The treaty was signed in 1786 and ratified by the United States in 1787. It established peace, friendship, and commercial arrangements between Morocco and the new United States.
France became the first major power to recognize the United States through the Treaty of Alliance in 1778, but it was not the first country overall. Spain and the Dutch Republic also supported the American cause and recognized the new nation later in the Revolutionary period.