ISTANBUL — Russia’s ambassador to Turkey was assassinated at an Ankara art exhibit on Monday evening by a lone Turkish gunman shouting “God is great!” and “don’t forget Aleppo, don’t forget Syria!” in what Russia called a terrorist attack.
The gunman, described by Ankara’s mayor as a policeman, also wounded at least three others in the assault on the envoy, Andrey G. Karlov, which was captured on Turkish video. Turkish officials said the assailant was killed by other officers in a shootout.
The assassination, an embarrassing security failure in the Turkish capital, instantly vaulted relations between Turkey and Russia to a new level of crisis over the Syrian conflict on Turkey’s southern doorstep, now in its sixth year.
The longer-term implications for the Russia-Turkey relationship, which had been warming recently after plunging a year ago, were not immediately clear. But some analysts played down the notion that the assassination would lead to a new rupture, saying it could conversely bring the countries closer together in a shared fight against terrorism.
President Vladimir V. Putin of Russia said on Russian television that Mr. Karlov had been “despicably killed” in a provocation meant to disrupt ties with Turkey.
In an emergency meeting with Foreign Minister Sergey V. Lavrov and other top officials, Mr. Putin said, “There can be only one answer to this: stepping up the fight against terrorism, and the bandits will feel this.”
The assassination came after days of protests by Turks angry over Russia’s support for Syria’s government in the conflict and the Russian role in the killings and destruction in Aleppo, the northern Syrian city.
The Russian envoy was shot from behind and immediately fell to the floor while speaking at an exhibition of photographs, according to multiple accounts from the scene, the Contemporary Arts Center in the Cankaya area of Ankara.
The gunman, wearing a dark suit and tie, was seen in video footage of the assault waving a pistol and shouting in Arabic: “God is great! Those who pledged allegiance to Muhammad for jihad. God is great!”
Then he switched to Turkish and shouted: “Don’t forget Aleppo, don’t forget Syria! Step back! Step back! Only death can take me from here.”
Turkish officials said the gunman was killed after a shootout with Turkish Special Forces. His identity was not immediately known.
Russia’s Foreign Ministry spokeswoman, Maria Zakharova, told the Rossiya 24 news channel that Mr. Karlov had died of his wounds in what she described as a terrorist attack. Turkey’s Interior Ministry said the ambassador had died at Guven Hospital in Ankara.
Russian news agencies said the ambassador’s wife fainted and was hospitalized after learning of her husband’s death. They also said Russian tourists in Turkey had been advised against leaving their hotel rooms or visiting public places as a precaution.
Russia’s Tass news agency said Mr. Karlov had been shot from behind while finishing remarks at the opening of an art exhibition titled “Russia Through Turks’ Eyes.”
Mr. Karlov, who started his career as a diplomat in 1976, worked extensively in North Korea over two decades, before moving to the region in 2007, according to a biography on the Russian Embassy’s website. He became ambassador in July 2013.
The attack was a rare instance of an assassination of a Russian envoy. Historians said it might have been the first since Pyotr Voykov, a Soviet ambassador to Poland, was shot to death in Warsaw in 1927.
For many Russians, the assassination is likely to recall the 19th-century killing in Tehran of Aleksandr Griboyedov, a poet and diplomat who died after a mob stormed the Russian Embassy. That episode is remembered as the most severe insult to Russia’s diplomatic corps in the country’s history.
More recently, the Lebanese Shiite militia Hezbollah, now allied with Russia in Syria, kidnapped four Soviet diplomats in 1985, killing one and releasing three a month later.
The United States, which has tangled bitterly with Russia over the Syrian conflict, quickly condemned the assassination in Ankara. In a statement, Secretary of State John Kerry called it a “despicable attack, which was also an assault on the right of all diplomats to safely and securely advance and represent their nations around the world.”
Other prominent officials who often criticize Russia’s actions in Syria and elsewhere also offered their condolences. “No justification for such a heinous act,” Jens Stoltenberg, the secretary general of NATO, wrote on Twitter. Secretary General Ban Ki-moon of the United Nations said in a statement that he was “appalled by this senseless act of terror.”
The assassination also illustrated the long reach of the Syrian war. It has destabilized Europe with hundreds of thousands of refugees, spawned terrorist attacks in Paris and Brussels, and led to the rise of the Islamic State, which controls territory across Iraq and Syria.
When the war began, Turkey was rising and confident, and Recep Tayyip Erdogan, then its prime minister, began supporting rebels seeking the ouster of the Syrian president, Bashar al-Assad. Entirely preoccupied with bringing Mr. Assad down, Turkey opened its borders to weapons and fighters flowing to the rebels, turning a blind eye, for a time, when the opposition turned increasingly Islamist.
As the war ground on, the consequences for Turkey were profound. It was overwhelmed with refugees — more than three million now reside in the country — and the rise of the Islamic State led to terrorist attacks within Turkey’s borders.
In the fall of 2015, with Mr. Assad confronting multiple challenges at home, Russia entered the conflict in support of the Syrian government, reinforcing Mr. Assad at a weak moment and dealing a blow to Turkey’s ambitions in Syria. Relations between Turkey and Russia reached a low point in November 2015 after Turkey shot down a Russian jet near the Syrian border.
But this year, in an effort to restore relations, Mr. Erdogan, now the president, met with Mr. Putin in St. Petersburg, and ever since the two countries have largely put aside their differences on Syria and focused on improving economic ties. In August, when Turkey’s military went into Syria to push the Islamic State out of the border town of Jarabulus, the move was widely seen as having been made with the tacit approval of Russia.
For Turkey the episode resonated in the Turkish collective memory: Turkey lost many diplomats in the 20th century to Armenian militants in a campaign of assassination in revenge for the Armenian genocide during World War I.
“Turkey is very aware of the size of this failure, and I think the government will make every effort to investigate this fully,” Sinan Ulgen, a former Turkish diplomat who is the chairman of the Center for Economics and Foreign Policy Studies, an Istanbul research organization, said of the Russian diplomat’s assassination. “I don’t expect any crisis between Turkey and Russia.”
Since the Turkish military incursion into Syria in August, Mr. Erdogan’s criticism of Russia over Syria had been muted. But Mr. Erdogan faced a dilemma: Even as he was warming to Russia, he faced a Turkish public, not to mention the Syrian refugees within Turkey, angry over Russia’s role in the bombing of Aleppo.
On Monday evening in Istanbul, just after the assassination, a group of protesters gathered outside the Russian consulate on Istiklal Avenue, the city’s largest pedestrian street. The gathering was more street theater than protest, with two men lying on the street, shrouded in bloody sheets and the Syrian flag, and surrounded by candles, to represent the killings in Aleppo.
Mohammed al-Shibli, a Syrian activist who participated, said, “I felt extreme happiness when I heard the news” of the assassination.
He continued: “This is the first step in getting justice for the Syrian people. The ambassador is not innocent. He represents the foreign policy of his murderous state and thus he is a murderer, as well. Now we are waiting for revenge against everyone who shed blood in Syria.”
Correction: December 19, 2016
An earlier version of this article misidentified the government that has collaborated with Russia even though it backs a different side in the Syrian conflict. It is Turkey, not Syria.