On Monday, NATO ally Turkey withdrew its ambassador from Washington. The severe step is meant to punish the U.S. for opening an embassy in Jerusalem on Monday.

Also Monday, Turkey expelled Israel’s ambassador to Turkey. It had already withdrawn its ambassador from Tel Aviv.

In a speech at Chatham House on Monday, Turkish President Reçep Tayyip Erdogan called Israel a “terror state,” and accused Israel of carrying out a “genocide.”

Indicating his view that the U.S. is also responsible for the so-called “genocide,” Erdogan said, “I condemn this humanitarian drama, this genocide, from whichever side it comes, Israel or America.”

Turning his attention to Washington, Erdogan accused the U.S. of violating international law by recognizing Israel’s capital and moving its embassy to Jerusalem. He insisted that following the embassy move, the U.S. can no longer mediate the Palestinian conflict with Israel.

As Erdogan was condemning Israel and the U.S. in London, protesters in Ankara were burning Israeli and American flags at a mass rally. One speaker at the rally referred to the American people as “dogs.” The rally was organized by Turkey’s Islamist IHH group. IHH, which is aligned with Hamas and al Qaeda, has close relations with the Erdogan regime.

Also Monday, Turkey called an emergency meeting of the Organization of the Islamic Conference (OIC) in Istanbul. Turkish Prime Minister Binali Yildirim said that immediately after the conference, a mass protest against Israel would be held at Istanbul’s central thoroughfare.

It would be easy to dismiss Erdogan’s latest moves as simply another expression of his hatred for Israel and Jews. By this line of thinking, the Turks are not hostile towards U.S. per se when Erdogan accuses the U.S. of committing genocide, and Turkish pro-regime demonstrators burn the U.S. flag. Erdogan and his followers are just sore at Washington for siding with the Jews.

That is, Erdogan’s anti-Americanism is a function of his anti-Jewish bigotry.

While it is certainly true that Erdogan is a raging anti-Jewish bigot and hater of Israel, antisemitism is only a partial explanation of his behavior.

On Thursday, Israeli Minister of Tourism Yariv Levin offered another explanation. After calling for Israelis to forego travel to Turkey, Levin said that Erdogan is striking out against Israel – and presumably the U.S. – as part of his election campaign. (Next week Turkey is holding parliamentary elections.)

Levin said, “Unfortunately, Turkey has a leader who repeatedly exploits Israel to make headlines for himself and to mobilize support ahead of elections. I would view the steps that Turkey has taken in terms of [next week’s] elections.”

The problem with explanations like Levin’s or the notion that Turkey’s anti-Americanism stems entirely from its hatred of Israel is that they ignore Erdogan’s view of elections on the one hand, and the purpose of his anti-Israel and anti-Jewish policies and his anti-Americanism on the other hand.

In regards to elections, Erdogan has made clear repeatedly over his 16 years in power that he will not allow election results to determine Turkey’s trajectory. In June 2015 elections, Erdogan’s Islamist AKP party lost its parliamentary majority. Rather than accept the loss, he called for new elections. Those elections, held in November 2015, unsurprisingly brought the desired results.

In an interview with Bloomberg on Tuesday, Erdogan would not rule out — indeed he all but admitted — that he will repeat the practice in the event his ruling AKP party fails to retain its parliamentary majority in the coming poll.

So, contrary to Levin’s assessment, Erdogan really doesn’t care about elections. His latest diatribes and actions against Israel and the U.S. do not stem from electoral considerations.

As for the role his Jew-hatred plays in determining his policies towards Israel and the U.S., while it is possible, indeed probable, that some of his policies are the result of his vituperative hatred of all things Jewish, the fact is that Erdogan uses hatred of Jews, which is widely shared by more than 70 percent of Turks, to advance a much larger goal.

To understand that goal, it is important to recognize Erdogan’s history with various U.S. administrations.

Erdogan was upheld by both the Bush and Obama administrations as a paragon of a moderate Muslim leader. To secure U.S. support, Erdogan was perfectly happy to let them believe that. But while he was basking in the support of the likes of Condoleezza Rice and Barack Obama,(who referred to Erdogan as one of five foreign leaders with whom he had formed “bonds of trust”), Erdogan repeatedly rejected the notion that there is such a thing as moderate Islam.

Erdogan never has made his true goal a secret. In his 16 years in power, he has enacted a slow motion revolution in Turkey. The Turkey he took over in 2002 was the secular republic formed by Ataturk on the ruins of the Ottoman Empire in the aftermath of World War I. Ataturk appointed the Turkish military as the constitutionally-mandated guardian of Turkey’s new secular order.

Military protection of secularism was necessary because, as Samuel Huntington explained in his book Clash of Civilizations and the Remaking of the World Order, Turkey was always a “torn” society. It was never able to strike a balance between Islam, secularism, and Western identity.

Turkish scholar and former Pentagon official Harold Rhode explains in the book Ally No More: Erdogan’s New Turkish Caliphate and the Rising Jihadist Threat to the West that Erdogan represents the majority of Turks who never accepted the regime’s secularism. Since entering office, he has used public support as well as U.S. backing to dismantle the secular state over time. He replaced the secularists who controlled the media, the judiciary, civil service, law enforcement, and education with Islamists who share his goal of transforming Turkey into an Islamic state. The failed July 2016 coup gave Erdogan a pretext to purge the military brutally of all pockets of secular resistance.

Erdogan’s aspirations are not limited to Turkey. Indeed, Rhode explains, his goals extends far beyond Turkey. Erdogan intends to restore the Ottoman Empire and install himself as the caliph, or leader of the Islamic world.

As Rhode notes, Erdogan made his aspirations clear during a victory speech following his reelection to a third term as Turkish prime minister in 2011. Erdogan said, “Today, our victory here in Turkey is as important [here] as it is in Sarajevo [the capital of Bosnia]; in Izmir [Turkey] as it is in for Beirut, this victory is as important in Ankara as it is in Damascus…in Turkey as it is in Ramallah, Jenin and in Jerusalem.”

Like the Iranian regime, which shares Erdogan’s ambition to lead the Islamic world, the chief sociological obstacle Erdogan faces in achieving his goal of leading the Islamic world is that Turkey is not an Arab state. To overcome this racial impediment, Erdogan has latched onto Islamic hatred of Israel and of the Jews as a means to prove his worth.

Thus Erdogan competes with the Iranian regime for the mantle of Hamas’s chief sponsor. Hamas’s operational headquarters are in Istanbul. Most of the lethal terror attacks the group carried out against Israelis in recent years were directed from Hamas offices in Turkey. Turkey serves as a hub for financial transfers and money laundering operations for Hamas. And Erdogan is Hamas’s chief advocate in international forums.

For Erdogan, propagating hatred for America is another key feature of his efforts to seize leadership of the Islamic world. Since entering power, he has inculcated deep-seated hatred of the West generally, and the United States specifically, into Turkish society. Television shows, movies and books have been released that spew conspiracy theories demonizing Americans and America.

It seems a day doesn’t go by without Erdogan or one of his underlings saying or doing something deeply hostile to Israel, or a report emerging about another Turkish policy adopted to harm the Jewish state. Likewise, it seems a a week doesn’t go by without Erdogan saying or doing something deeply hostile to the U.S., its citizens, or its strategic interests.

This week, Israel’s foreign ministry debated whether or not to cut off diplomatic relations with Turkey altogether. As Deputy Foreign Minister Tzipi Hotovely explained in a radio interview Thursday, the decision was made to keep formal ties intact. Most of the flights of Israel’s national airline, El Al, overfly Turkish airspace, Israel has considerable trade with Turkey, and Turkey has a significant Jewish community that is increasingly at risk, she explained.

While this is all true, given Erdogan’s desired end state, it is clear that Israel should have contingency plans ready to surmount the challenges to air travel and trade for the day Erdogan cuts off relations with Jerusalem.

Parallel to Israel’s discussions, it is reasonable to assume that Erdogan’s viciously anti-American statements and actions have provoked Washington policymakers to conduct cost-benefit analyses of Turkey’s continued membership in NATO. The reasoning presumably concludes that it is better for the U.S. to betray its Kurdish allies in Syria and Iraq and other shocking displays of Turkish treachery than lose its bases in Turkey.

While these considerations are not ridiculous, like Israel’s assessment of the desirability of continued diplomatic ties to Erdogan’s Turkey, they are largely missing the point.

Sixteen years ago, Erdogan launched Turkey on a trajectory that is implacably hostile and antithetical to the very notion of a Turkish-U.S. alliance, let alone to continued Turkish membership in NATO.

Unless U.S. cost-benefit analyses are based on that basic fact, their conclusions are largely irrelevant to the strategic challenge Erdogan’s Turkey poses to the U.S.

Caroline Glick is a world-renowned journalist and commentator on the Middle East and U.S. foreign policy, and the author of The Israeli Solution: A One-State Plan for Peace in the Middle East. Read more at www.CarolineGlick.com.