Morocco was one of the first countries to recognize the newly independent United States, opening its ports to American ships by decree of Sultan Mohammed III in 1777. Morocco formally recognized the United States by signing a treaty of peace and friendship in 1786, a document that remains the longest unbroken relationship in U.S. history.
Source: https://www.state.gov/u-s-relations-with-morocco/