Andrei Karlov died of his wounds after the shooting, which occurred on the eve of a key meeting between the Russian, Turkish and Iranian foreign ministers on the Syria conflict.
Dramatic television footage showed a man in a dark suit and tie waving a gun and gesturing in the air at the Ankara exhibition hall.
The state-run Anadolu news agency said the gunman had been "neutralized" in a police operation, without giving further details.
"Today in Ankara as a result of an attack the Russian ambassador to Turkey Andrei Karlov received wounds that he died from," ministry spokeswoman Maria Zakharova said in televised comments. "We qualify what happened as a terrorist act."
The Kremlin said President Vladimir Putin had been informed of the attack.
The incident came after days of protests in Turkey over Russia's role in Syria, although Moscow and Ankara are now working closely together to evacuate citizens from the battered city of Aleppo.
Pictures published by the Hurriyet daily showed at least two men in suits lying flat on the ground as another man brandished a gun.
The mayor of Ankara identified the attacker as a Turkish policeman.
The shooting took place at Cagdas Sanatlar Merkezi, a major art exhibition hall in the Cankaya district of Ankara where most foreign embassies are located, including Russia's mission.
"It happened during the opening of an exhibition," Hurriyet correspondent Hasim Kilic, who was at the scene, told AFP.
"When the ambassador was delivering a speech, a tall man wearing a suit, fired into the air first and then took aim at the ambassador," said Kilic.
"He said something about Aleppo and 'revenge.' He ordered the civilians to leave the room. When people were fleeing, he fired again," he added.
Protesters in Turkey have held Moscow responsible for human rights violations in Aleppo.
Turkish Interior Minister Suleyman Soylu was at the scene to supervise a police operation, Turkish television said.
Turkey and Russia saw relations plunge to their worst levels since the Cold War last year when a Turkish jet shot down a Russian warplane over Syria.
They stand on opposite sides of the Syria conflict with Ankara backing rebels trying to topple Moscow-ally, President Bashar al-Assad.
But the rhetoric has warmed considerably since a reconciliation deal was signed earlier this year and a Russian and Turkish-brokered deal has helped the evacuation of citizens from Aleppo in the last days.
The attack comes a day before Turkish Foreign Minister Mevlut Cavusoglu, Russian counterpart Sergei Lavrov, and Foreign Minister Mohammad Javad Zarif of Iran, Assad's other key ally, were to hold unprecedented tripartite talks on the Syria conflict in Moscow.
A Turkish official on Monday denied Ankara had forged any secret "bargain" with Moscow over the future of Syria, despite the improving cooperation that led to the deal for evacuations from Aleppo.