Well the Treaty of Marrakech didn't take place until 1786, five years after the American Revolution had ended, and in reality it was just a way of formalizing a process that started during the war during the U.S. very dark year of 1777. The Sultan of Morocco was seeking to increase trade with all the major powers to grow commerce and industry in his country, and so he published a list of countries in 1777 whose ships would be welcomed in his ports. He added the fledgling 1 year-old United States on to the list, probably just to cover his bets. This was a bit of a ballsy thing to do, since the American Revolution was still in full blaze and American victory, especially in 1777, was by no means assured. This made Morocco the first country however to sort of back-handed recognize the U.S. as a country. This irked the British to no end, but there wasn't much they could do about it. This sort of low level diplomatic recognition was noted by the U.S. Continental Congress at the time. However, it wasn't immediately particularly useful, as Congress had their hands full at the time trying to figure out how to feed George Washington's starving troops in Valley Forge and stop losing battles.
It was only 9 years later in 1786, that the U.S. formally reached out to Morocco and returned the favor. After an exchange of envoys, the two countries created the Moroccan-American Treaty of Friendship, which despite being sorely tested 15 years later in the Barbary Wars when pirates hid out in Moroccan ports, remains in force even today as the longest standing treaty that the U.S. has had with any foreign government.