Can Dundar, the former editor in chief of the leading Turkish newspaper Cumhuriyet, is now living in exile.

This month, as Russia and Turkey teetered on the edge of a direct military confrontation in Syria, Vladimir Putin welcomed Recep Tayyip Erdogan, his Turkish counterpart, to the Kremlin — but I don’t think “welcomed” is the right word.

A 120-second video clip broadcast on Russian state TV triggered an uproar in Turkey. In the footage, Erdogan and his delegation are seen waiting in the Kremlin to meet with Putin. To be more precise, they’re being forced to wait. Their unhappiness is written all over their faces. At one point, Erdogan gets tired of standing and takes a seat. Pro-Erdogan media noted that Putin is notorious for this sort of thing. This time, though, Russian television made sure to dispatch several cameras to document the scene, complete with a superimposed countdown clock. It was simply a humiliation.

Erdogan was supposed to be in Moscow to demand accountability. On Feb. 27, Syrian forces, operating with Russian support, killed 36 Turkish soldiers in northern Syria. There were fears that Erdogan would declare war. In the end, though, he chose to go to Putin in order to ease tensions. This made the wait before the meeting even more painful for Erdogan. When the Turkish president returned from Moscow empty-handed, he was greeted with scathing commentary.

Turkey lost soldiers in an attack that Russians were partners in, and in spite of this Erdogan went to meet with the Russians. This was merely the latest episode in a complicated relationship that, over the past five years, has alternated between overtures of friendship and outright hostility.

The two countries experienced a spike in tensions in November 2015, when Turkey shot down a Russian plane that had apparently breached its airspace, and reached a breaking point when Putin accused Turkey of trading gas with the Islamic State. In contrast to European leaders, Putin accompanied his words with economic force, implementing a tourism and trade embargo that forced Erdogan to apologize eventually.

Then some of Erdogan’s internal foes attempted a coup against him. As that night went on, with Western leaders silently waiting to see what would happen, Putin was the one to send Erdogan a message of support. In a radical shift in his country’s foreign policy, the grateful Turkish leader decided to forge a close new relationship with Moscow. In the course of the next 2½ years, Erdogan and Putin met 12 times.

Trade and tourism between Russia and Turkey grew rapidly. With the help of showcase projects such as the TurkStream pipeline, designed to carry Russian natural gas to Turkey, or Akkuyu, set to become Turkey’s first nuclear power plant, Moscow and Ankara went from being rivals to friends virtually overnight. Erdogan had finally found a partner who didn’t ask pesky questions about human rights, rule of law or freedom of the press. Putin didn’t insist on parliamentary approval for executive decisions and send Erdogan letters saying, “Don’t be a fool.”

Syria played an important role in this new relationship. Russia had filled the vacuum left by the U.S. decision to pull out of Syria. Turkey, feeling threatened, applied for Patriot missiles from the United States but was insistently rejected. Ankara began to feel isolated by the West.

In this period, Putin took Erdogan in his claws by inviting Turkey, along with Iran, to the Astana talks on Syria. He was thus able to pull a NATO ally to his side and strengthen his own position. In July 2017, Erdogan alarmed NATO by announcing his deal with Russia to buy S-400 missile defense systems. This was the first time that a member of the transatlantic alliance had signed such an arms deal with Russia.

Erdogan ignored criticism; he thought that he was playing a masterful game by signaling to the West that he had alternatives. Yet he deluded himself about Putin’s reliability. As Turkey weakened its ties to the West, Putin started insisting that Erdogan give up on his animosity to the regime of Bashar al-Assad and demanded that he stop supporting radical Islamist militias. Last month’s attack on Turkish soldiers was the logical consequence. Putin saw that Erdogan was left with no options other than Russia.

The West’s first reaction was to remind Turkey of the unreliability of its new friend. In a bind, Erdogan played his last card and opened the borders for refugees, which he had been using to blackmail Europe for a long time. But even this last move, which put hundreds of thousands of lives on the line, backfired. After traveling to Brussels last week to discuss the refugee issue with European Union officials, Erdogan walked out of the meeting when the parties failed to reach an agreement.

For quite some time now, Erdogan has been playing a dangerous game of balancing the West and Moscow against each other. In the end, he seems to have lost both. Perhaps now he will have a fresh appreciation of a famous adage of Turkish diplomacy: “In the Middle East, if you’re not on the invitation list for an important dinner, you should check the menu. Your name might be on it.”

Read more: