Andriy Portnov, 51, was previously a senior aide to a pro-Russian former Ukrainian president, Viktor Yanukovich, who was ousted in a 2014 popular uprising.
Police reached the scene after receiving calls on Wednesday morning about a man with gunshot wounds on the street outside the American School of Madrid, in the Pozuelo de Alarcon suburb west of the capital, police officials told Reuters.
"Several persons shot him in the back and the head and then fled towards a forested area," an interior ministry source said.
When emergency services arrived they found Portnov dead with at least three gunshot wounds, a spokesperson said.
Police had cordoned off the pavement outside the school and several ambulances were parked nearby.
Portnov left for Russia in 2014 and faced investigations in Ukraine over accusations of treason and embezzlement.
He was targeted with European Union sanctions, although those and the charges were later dropped.
The US Treasury Department put Portnov on its sanctions list in 2021, saying he had "cultivated extensive connections to Ukraine's judicial and law enforcement apparatus through bribery".
Portnov appeared to have been living in Madrid since at least April 2024 when he signed a power of attorney form in the Spanish capital related to a property transfer in Ukraine to his children, a Radio Free Europe/Radio Liberty report said.
Since Russia's full-scale invasion of Ukraine in February 2022, there have been several high-profile crimes related to Russia and Ukraine in Spain, which has significant expatriate communities from both countries.
In 2022 a retired Spanish civil servant sent six letter bombs to targets around Spain, including to Prime Minister Pedro Sanchez, the Ukrainian and US embassies and government offices.
Pompeyo Gonzalez Pascual, whose social media searches suggested sympathy for Russia, was convicted and jailed for the offences in 2024.
In February 2024, a Russian pilot who had defected to Ukraine with his helicopter was found dead from multiple gunshot wounds in the parking garage of his apartment block near Alicante in southeastern Spain.