News broke Thursday of a diplomatic agreement between Israel and Morocco. As part of what the Trump administration calls its Abraham Accords, Morocco will join Bahrain and the United Arab Emirates in normalizing relations with Israel. To facilitate this diplomatic rapprochement between the North African kingdom and Israel, the Trump administration reversed a long-standing U.S. policy by formally recognizing Moroccan control over the Western Sahara.

Morocco has effectively held power over the Western Sahara since 1975, when Spain ended its colonial occupation. Since then, about 500,000 Moroccan settlers have made a home in this arid land, and Moroccans now outnumber the local Saharawi by about 2 to 1.

Yet no state has countenanced Morocco’s right to annex the mineral-rich territory, which, is the size of Colorado and is strategically situated along 700 miles of the Atlantic coast. The Saharawi people still claim their right to rule a sovereign state, and the U.N. recognizes the Polisario Front as legitimately representing these political claims. One month ago, Moroccan troops entered a demilitarized zone, and Polisario leaders claimed Morocco had broken a cease-fire agreement from 1991. So, the Saharawis are now actively engaged in an armed conflict with Morocco.

Morocco recognized the United States in 1777,” tweeted President Trump on Thursday morning, justifying, “it is thus fitting we recognize their sovereignty over the Western Sahara.” By citing a 1777 letter by Sultan Muhammad ben Abdallah (r. 1757-1790), Trump has framed this new agreement as a continuation of historic ties between the U.S. and Morocco. Yet, in anchoring U.S. policy to this ancient letter, it seems the current ruler, King Mohammed VI has outmaneuvered American leaders, just as surely as did his 18th-century forebear.

On Dec. 20, 1777, Sultan Muhammad ben Abdullah informed the diplomatic community in Morocco of a royal edict allowing “free entry in his ports” of Americans and other marginal players, like merchants from the long-forgotten city-state of Leghorn (now Italy’s Livorno).

Sea raiding was common, and British treaties did not protect American ships after the Declaration of Independence. Muhammad ben Abdallah’s diplomatic recognition most certainly helped merchants from the rebellious colonies do business in the prosperous Mediterranean.

Yet Muhammad ben Abdallah’s support was scarcely motivated by an altruistic desire to help a political underdog spread its democracy. The Sultan instead sought to solidify his rule over Morocco after what had been decades of internecine fighting among contenders for the throne.

To stabilize the Alawite monarchy, the Sultan sought to defuse the covetous aspirations of Mediterranean powers. In 1769, he took back from the Portuguese Mazagan, now El Jadida. Five years later, the Sultan tried to drive Spain from its North African enclave. British assistance, however, never materialized as promised, and Morocco lost the Battle of Melilla in 1774. The Ottomans loomed large, which explains in part the Sultan’s construction of Essaouira at that time, since it allowed Morocco to become more involved in Atlantic trading networks.

After Britain recognized American independence in 1783, Muhammad ben Abdallah was eager for the U.S. to make a treaty with Morocco. However, the government in this early Revolutionary era dragged its heels. After waiting for more than a year for some tangible diplomatic overture, Muhammad ben Abdallah took matters into his own hands.

In fall 1784, Sultan ordered his sea raiders to board the American merchant ship, The Betsey. His men took the ship to Tangier, and the Sultan made it known that until “a peace should be concluded with them, the aforesaid vessel shall be delivered up with whatever it contains.”

The Sultan assured the U.S. government that this seemingly hostile gesture was not intended to demonstrate any ill will, but, instead, to act as a reminder of his sincere desire for peace.

Secretary of State John Jay consequently authorized Thomas Jefferson and Benjamin Franklin to negotiate the Moroccan-American Treaty of Friendship, signed in June 1786. Ensuring more than trading rights, the treaty guaranteed Morocco that the U.S. would not join potential enemies in the Mediterranean region, since the two countries agreed that “If either of the Parties shall be at War with any Nation whatever, the other Party shall not take a Commission from the Enemy.”

Since that time, Morocco and the U.S. have remained political allies. In 1821, the US established a diplomatic mission in a relatively modest courtyard house in Tangier, which, today is the only historic landmark in a foreign country maintained by the U.S. Department of the Interior.

In 1912, when the French colonized Morocco, the U.S. would not recognize the Protectorate, not until 1917, when an American alliance with the Entente necessitated normalizing relations between the U.S. and France. But 26 years later, during the Casablanca Conference of 1943, President Franklin D. Roosevelt, much to the chagrin of French officers, dined privately with the king, Moulay Muhammad ben Youssef. His son, Hassan II, father of the current king, in turn, allowed the U.S. to establish military bases in Morocco during the Cold War.

There has always been a quid pro quo relationship between the U.S. and Morocco, but perhaps the current Moroccan king, Mohamed VI, has gotten more “quid” than “pro quo.”

After all, Morocco is not really changing its policies, merely making them more public. Israelis have discreetly operated a diplomatic office in Casablanca for many years. Israelis and Moroccans can visit each other’s country with their respective national passports. Morocco encourages Jewish tourism, and it has two — soon to be four — national museums devoted to Morocco’s Jewish heritage. In fact, some 50,000 Israelis travel annually to this kingdom, keen to discover all the sites in an Arab land that celebrates its Jewish heritage.

Ordinary Moroccans may welcome tourists from Israel, but they balk at the idea of undermining the lot of Palestinians. Few Moroccans have probably considered the strong parallels between Israelis in the West Bank and Morocco’s occupation of — and settlements in — Saharawi lands. But the king has arranged for U.S. recognition of Morocco’s control over the Western Sahara, which will make his royal overtures toward Israel more palatable.

The U.S. has provided Muhammad VI exactly what he wants. According to President Trump, his “proclamation recognizing Moroccan sovereignty over the Western Sahara … is the only basis for a just and lasting solution for enduring peace and prosperity!” There could not be a more decisive statement of Morocco’s effective use of the U.S. to accomplish its foreign policy goals.

Morocco has been an ally of the U.S. from the start, but, make no mistake, the king has never been an American lackey. Alawite rulers have long proved shrewd diplomats, and last Thursday, Muhammad VI, once again, just as his ancestor, Muhammad ben Abdallah, got the better of American leaders.