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.
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” to sabotage ties with Turkey. Mr. Putin spoke with the Turkish president, Recep Tayyip Erdogan, by phone, and the two leaders agreed to cooperate in investigating the killing, and in combating terrorism broadly.
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.
In the fall of 2015, 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 Turkey’s 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 Ankara attack resonated in the Turkish collective memory: Turkey lost many diplomats in the 20th century to Armenian militants in a campaign to avenge 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 Turkish former 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.”
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.
Tim Arango reported from Istanbul, and Rick Gladstone from New York. Reporting was contributed by Ivan Nechepurenko, Oleg Matsnev and Andrew E. Kramer from Moscow, Safak Timur and Karam Shoumali from Istanbul, Sewell Chan from London, Gardiner Harris from Washington and Bryant Rousseau from New York.