ANDREI KARLOV, the Russian ambassador to Turkey, was only moments into his speech at an art gallery in Ankara, Turkey’s capital, on December 19th when the man standing behind him, disguised as a member of his security team, fired the first bullet into his back. His assassin, identified as an off-duty Turkish police officer, claimed to be retaliating for Russian war crimes in Syria. “We die in Aleppo, you die here,” he shouted. He also repeatedly invoked the Prophet Muhammad, before dying in a shoot-out with other policemen.

The attack came amid largely peaceful protests in Turkish cities against Russian military intervention to prop up President Bashar al-Assad in Syria.

Recep Tayyip Erdogan, Turkey’s president, and his Russian counterpart, Vladimir Putin, both referred to the shooting as “a provocation” and pledged to strengthen co-operation against terrorism. The Turkish foreign ministry said it “would not allow” the assassination to damage relations, while officials also confirmed that a meeting between the Turkish, Russian and Iranian foreign ministers to discuss the situation in Syria, scheduled to take place on December 20th in Moscow, would go ahead.

Mr Karlov was posted to Ankara in 2013 and remained there even after Turkey’s air force shot down a Russian fighter-jet near the Syrian border in November 2015. Mr Erdogan apologised for the incident and met Mr Putin in St Petersburg over the summer. The two sides have since initiated a rapid detente, signing a pipeline deal and pledging to upgrade economic relations.

They have also found some common ground in Syria. That has been no easy task. Turkey has backed Islamist rebels against the Assad regime since the start of the war. Russia has bombed them for over a year. Yet it was with Russia’s blessing that Mr Erdogan’s troops were able to enter northern Syria in August, pushing Islamic State (IS) jihadists—and Kurdish fighters—from the border area. More recently they negotiated a ceasefire and an evacuation from east Aleppo, besieged for months by Syrian and allied forces.

As The Economist went to press, it remained unclear whether Mr Karlov’s killer had been out to avenge Russia’s actions in Syria, as he proclaimed, or to subvert ties between Turkey and Russia, as officials on both sides suggested, and whether he had acted alone. Some Turkish officials immediately pointed a finger at the Gulen movement, a sect accused of spearheading a failed coup attempt that killed 270 people in July.

Turkey has been reeling from terrorist violence since 2015, when an IS suicide-bomber helped bring down a fragile ceasefire between security forces and Kurdish insurgents. Mr Karlov’s murder, the first of a foreign envoy on Turkish soil, may have wider ramifications. Western countries are right to worry about the extent of Turkey’s rapprochement with Russia, yet they have even more reason to hope that Mr Erdogan and Mr Putin do not come to blows. The two strongmen appear to be doing the their best to contain tensions. Their relationship may emerge from the ambassador’s death stronger than ever.