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 the leaders of Turkey and Russia called a provocative terrorist attack.
The gunman, described by Turkish officials as a 22-year-old off-duty police officer, also wounded at least three others in the assault on the envoy, Andrey G. Karlov, which was captured on video. Turkish officials said the assailant was killed by other officers in a shootout.
The assassination, an embarrassing security failure in the Turkish capital, forced Turkey and Russia to confront a new crisis tied directly to the Syrian conflict, now in its sixth year.
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.”
Mr. Erdogan, in a speech late Monday night, said the assassination was a provocation meant to derail efforts by Turkey and Russia to collaborate more closely on regional issues and economic ties.
“We know that this is a provocation aiming to destroy the normalization process of Turkey-Russia relations,” Mr. Erdogan said. “But the Russian government and the Turkish republic have the will to not fall into that provocation.”
The assassination came after days of protests by Turks angry over Russia’s support for the Syrian 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.”
Hasim Kilic, a Turkish photographer for the Hurriyet news organization who witnessed the attack and sold his images to Reuters, said in a telephone interview that the gunman had fired seven shots at the ambassador — “four from behind, three while the body was on the ground” — as guests screamed and scrambled to hide.
Mr. Kilic, who was crouched behind a cocktail table about 12 feet away, said the gunman had ordered everyone else out and refused a security guard’s request to drop his weapon. “Call the police, and I will die here,” Mr. Kilic quoted the assailant as saying.
Turkish officials said the gunman was killed after a shootout with Turkish Special Forces.
He was identified by Turkey’s interior minister as Mevlut Mert Altintas, from the western province of Aydin and a graduate of a police college in Izmir. Local news reports said that Mr. Altintas’s mother and sister had been arrested and that a computer had been confiscated from their house.
While it was too early to tell if the gunman acted alone, his use of jihadist slogans and his invocation of Syria raised the possibility that he was a member, or at least a sympathizer, of an Islamist group like Al Qaeda’s Syria affiliate or the Islamic State, two organizations that Turkey has been accused by allies, including the United States, of supporting in the past.
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 that as a precaution, Russian tourists in Turkey had been advised against leaving their hotel rooms or visiting public places.
Russia’s Tass news agency said that 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 changing regions 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, said on Twitter. Secretary General Ban Ki-moon of the United Nations said he was “appalled by this senseless act of terror.”
President-elect Donald J. Trump, who has been accused by critics of aligning with Russia, said in a statement that Mr. Karlov had been “assassinated by a radical Islamic terrorist.”
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 Mr. Erdogan, then its prime minister, began supporting rebels seeking the ouster of the Syrian president, Bashar al-Assad. 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.