In December 1777, the Moroccan Sultan Muhammad 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.
However, the citation being offered to the US State Department website does not support Wikipedia's claim, and Archive.org shows that it never did. The State Department says:
What country was the first to recognize the United States?
France recognized the United States as an independent state on February 6, 1778.
The citation is mistaken, but who is correct, Wikipedia or the State Department?
Let's look at an article entitled "Moroccan Sultan Sidi Muhammad Ibn Abdallah's Diplomatic Initiatives toward the United States, 1777-1786" (Proc. Am. Phil. Soc. 143(2) (1999), 233-265)
[In autumn 1777, the Moroccan] ambassador Tahar Abdulhaq Fennish was arriving in the bay of Marseilles on board a French ship ... British Consult Charles Logie [wrote] "I have reason to think that his Chief errand, to that Court, was to Negotiate a Peace with the [American] Rebel Agents."
Official American documents are silent on the subject, but according to the diary of Arthur Lee, the commissioner from Virginia, not only were the American representatives in France aware of Ambassador Fennish's presence in Paris, but the subject of meeting with him did come up. "Mr. Lee having often urged an application to the court to assist them in forming a treaty with the emperor of Morocco, while his ambassador was at Paris, it was at last agreed, after much difficulty, that Mr. Lee should go the next day to Versailles, and ask Mr. Girard's advice upon it. Next day he went accordingly. Mr. Girard said the Morocco ambassador was to quit Paris that very evening, and therefore nothing could be done." In truth, Tahar Fennish did not leave Paris until five days later.
It was in December 1777 that the turning point came for the United States' quest for French recognition. Upon receiving the news in early December of the Americans' victory at Saratoga in October, France made the momentous decision to go public in its support of the Americans ...
The conspiracy-minded might wonder if France deliberately kept the Americans and the Moroccans apart, or -- at best -- avoided bringing them together. It is just possible that France preferred to keep the Americans dependent on them for protecting against Barbary...
In a letter of 17 December addressed to General Eliott in Gibraltar, the sultan says that "he is at peace with the Americans and looks upon them and the English to be all the same, that if they have disputes amongst themselves, His Majesty had nothing to do with it." In apparent contradiction, he writes to General Eliott two days later, saying that "he was at peace with all of the English, except the Americans, who are rebels." But the next day, 20 December 1777, the sultan addresses a letter to the consuls and merchants of Tangier, listing countries with free access to Morocco's ports. The Americans are included.
The king of Morocco, Monseigneur, has had written by an English business man, who was in Meknes, to all the consults and merchants who are in his dominions, so that they could bring notice in Europe that this prince gives free entry in his ports to the nations of Russia, Malta, Sardinia, Prussia, Naples, Hungary, Leghorn, Germany and the Americans...
These three primary sources may sound contradictory and ambiguous (writing "the Americans" instead of "the United States"). Below, the article offers primary sources attesting that this was a purposeful strategy by the sultan who really was attempting to formally recognize the US but worried about political consequences of doing so at such an early stage, and likely facing pressure from France as well as Britain.
There is no indication that this was officially communicated to the Americans at the time, although a cryptic message from Charles W. F. Dumas makes us think it might have been. This fervently pro-American European was America's agent in The Hague. In a letter of 6 March 1778 to the American commissioners Dumas included several extracts from official Dutch despatches, including the reference to correspondent from "Webster Blount..."
The sultan seems to have wanted a formal relationship, but may have been concerned about the reaction from European powers. The official, but low-key, statement of 20 December 1777 could well have been a trial balloon. Webster Blount wrote the States General in a letter dated 25 February 1778 from Mogador that "the sultan's initial intention was to limit his declaration to the Americans, but he changed his mind and made the declaration more general..." The French consul downplayed the letter; and there appears to have been little or no other European reaction. Two months after the low-key declaration the sultan formally reissued it on 20 February 1778. This received wider distribution.
Quick summary: A Moroccan ambassador intended to meet the Americans in France and formally recognize them in autumn 1777 but was mysteriously prevented from meeting them by French intermediaries. In December 1777 Morocco formally recognized America. According to the historian quoted, this was an official, legal recognition by the Sultan but he purposefully kept this recognition quiet and hidden from European powers and sent them mixed messages in his formal letters, probably to prevent them from slapping him with sanctions or other punishments. In February 1778, after France recognized America, the Sultan made his recognition more open.
The Moroccan rumor that they were the first sovereign state to recognize the USA is technically accurate, which is the best kind of accurate.