He shouted “Allahu Akbar” – God is great – as he pulled the trigger, but was unclear whether he was inspired by the Islamic State of Iraq and the Levant (Isil) or the rebels who have finally been crushed in Aleppo after four years of war.

Reports in Turkey suggested he recited a message in Arabic similar to a phrase associated with the rebel group Al Nusra, the Syrian branch of al-Qaeda.

He was shot dead by police in a shoot-out that lasted 15 minutes. Three other people were wounded in the attack.

President Putin spoke on the phone to Turkey’s President Recep Tayyip Erdogan after the shooting and Moscow said it was “a tragic day in the history of our country and Russian diplomacy”.

Russia and Turkey, which back opposing sides in the Syrian civil war, had entered a diplomatic crisis when the Turkish air force shot down a Russian jet in November 2015, but in recent months Mr Putin and Mr Erdogan have been in regular contact, and have held talks about a general ceasefire in Syria.

Russian foreign ministry spokeswoman Maria Zakharova said: "We qualify what happened as a terrorist act. The murderers will be punished.

"Today this issue will be raised at the UN Security Council. Terrorism will not win out."

Shocked to hear of despicable murder of #Russia's Ambassador to #Turkey. My thoughts are with his family. I condemn this cowardly attack.

Boris Johnson, the Foreign Secretary, described the killing as "cowardly" and a "despicable murder”.

John Kerry, the US Secretary of State, said: “The United States condemns the assassination today in Ankara of Russian ambassador Andrei Karlov. We stand ready to offer assistance to Russia and Turkey as they investigate this 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."

Mr Karlov was several minutes into a speech at the launch of an exhibition of photography about Russia when the gunman opened fire, shooting him several times in the back.

A television camera that was still running after its operator had fled, recorded Altintas shouting in Arabic: “We have made an oath to Muhammad to die in martyrdom...a revenge for Syria and Aleppo.”

Hasim Kilic, a correspondent with Hurriyet newspaper who was at the event said: "It all happened very quickly. As the ambassador took to the lectern to speak, the attacker shouted a few things about Aleppo.

“People wanted to get out. The attacker fired in the air a few times. Then, aiming straight for the ambassador, he fired four or five shots. As far as I know, the ambassador doesn't go out and about with security protection. He's not that kind of ambassador. So he didn't have any security officers by his side. Nor were there any police inside the Modern Arts Centre. The attacker shouted some religious slogans as he opened fire.”

Gokcek, known for his outspoken comments, speculated on his official Twitter account that the policeman may have been a follower of Fethullah Gulen, the exiled Islamic cleric blamed for the July 15 coup aimed at toppling President Erdogan.

An investigation was underway last night to establish how the policeman-turned-killer was able to enter the art gallery when he was not scheduled to be on duty there. The art exhibition was sponsored by the Russian embassy, making it an obvious security problem.

China and UN condemn the killing

China's foreign minister expressed condolences to his Russian counterpart on the killing of the Russian ambassador to Turkey, calling the assassination a "barbaric act of terrorism."

Foreign Minister Wang Yi said that China strongly condemns such actions targeting diplomatic personnel and was "resolutely opposed to all kinds of terrorism."

Mr Wang said China is willing to work with the international community in "resolutely supporting" Russia's efforts to crack down on terrorism and will boost cooperation with Moscow on this front.

The United Nations Security Council also condemned "in the strongest terms" Karlov's killing, calling it a "terrorist attack" and calling for the perpetrators, organisers and sponsors to be brought to justice.

A statement onMonday night from the UN's most powerful body reaffirms that all forms of terrorism pose one of the most serious threats to international peace and security. It says "that any acts of terrorism are criminal and unjustifiable, regardless of their motivation, wherever, whenever and by whomsoever committed."

The council also expresses "deep condolences" to the family of ambassador and the Russian government.

Recep Tayyip Erdogan and Vladimir Putin both made televised statements on Monday night condemning the killing as an attempt to destroy a recent thaw between their countries and undermine the Syrian peace process.

"This murder is clearly a provocation aimed at undermining the improvement and normalization of Russian-Turkish relations, as well as undermining the peace process in Syria promoted by Russia, Turkey, Iran and other countries interested in settling the conflict in Syria," Mr Putin said.

Mr Putin said he and Mr Erdogan had agreed in a telephone conversation that a team of Russian investigators would fly to Turkey to investigate the murder, and demanded that they find out "who gave the orders."

He praised Mr Karlov as a "brilliant diplomat" and ordered the Russian foreign ministry to award him posthumous honours.

Mr Erdogan said Turkey-Russia relations were vital for the region and those who aimed to harm ties were not going to achieve their goals.

'He shouted a few things about Aleppo...then shot the ambassador"

Hasim Kilic, a correspondent with Hurriyet newspaper, was also at the event, writes Laura Pitel.

He said: "It all happened very quickly. As the ambassador took to the lectern to speak, the attacker shouted a few things about Aleppo. People wanted to get out.

"The attacked fired in the air a few times. Then, aiming straight for the ambassdor, he fired four or five shots. As far as I know, the ambassador doesn't go out and about with security protection. He's not that kind of ambassador. So he didn't have any security officers by his side.

"Nor were there any police inside the Modern Arts Centre. The attack shouted some religious slogans as he opened fire. The sound of gunfire continued for about half an hour after everyone escaped."

Another unnamed witness told the news site Diken: "There was a single attacker. He was wearing a suit. He said to the Russian ambassador: "I'm not going to get out of here alive. And neither are you." Then he took aim straight at him. We all ran out. The ambassador was motionless on the ground."

Gunman 'has links to Al Nusra'

According to Turkish media reports, the police officer who shot dead Andrey Karlov recited a message in Arabic which has a number of similarities with the unofficial 'anthem' of the rebel group Al Nusra, the Syrian branch of Al Qaeda.