In a piece of high diplomatic theatre, the Russian president defied expectations of a Cold War-style mutual expulsion and instead met the Obama administration's sanctions with a show of magnanimity.
Earlier Sergei Lavrov, the foreign minister, publically recommend that Russia expel 35 US diplomats and close down two US diplomatic compounds.
The move would have amounted to a tit-for-tat response to American sanctions.
The announcement provoked fury in Moscow, where many officials attacked Mr Obama personally for the move.
Dmitry Medvedev, the Russian prime minister, wrote on Twitter that the current administration was "ending its term in anti-Russian agony."
Maria Zakharova, a spokeswoman for the Russian foreign ministry wrote on Facebook: "Today America and the American people have been humiliated as their own President."
The Russian Embassy in London called it "Cold War deja vu", and said the US "wanted to destroy" ties with Moscow.
Mr Obama said the 35 expelled diplomats were "intelligence operatives".
He also announced it was closing two compounds owned by the Russian government, and used for intelligence operations, in New York and Maryland, from noon on Friday.
At the same time he ordered sanctions against Russia's GRU and FSB intelligence agencies, and six named Russian individuals.
They included Lt Gen Korobov, head of the GRU, and three of his deputies. The other two were Alexei Belan and Yevgeny Bogachev, two Russians wanted by the FBI for cyber crimes for years.
Also sanctioned were three computer companies alleged to have provided "material support" to the GRU.
Mr Obama accused Russia of "aggressive harassment" and said "all Americans should be alarmed by Russia's actions". He said hacking "could only have been directed by the highest levels of the Russian government".
Mr Obama said: "These actions follow repeated private and public warnings that we have issued to the Russian government, and are a necessary and appropriate response to efforts to harm US interests in violation of established international norms of behaviour. Such activities have consequences."
A US official added: "By imposing costs on the Russian diplomats in the United States, by denying them access to the two facilities, we hope the Russian government reevaluates its own actions."
It was understood that Russia's ambassador to the United States, Sergei Kislyak, will not be one of those expelled.
It comes after the the CIA and FBI concluded that Russia was responsible for hacking the Democratic Party and releasing embarrassing emails with the intention of helping Mr Trump to win the White House.
Mr Trump said he would meet intelligence officials next week to hear evidence of the Russian hacking.
He said: "It's time for our country to move on to bigger and better things.
"Nevertheless, in the interest of our country and its great people, I will meet with leaders of the intelligence community next week in order to be updated on the facts of this situation."
The US State Department said the expelled diplomats had been "acting in a manner inconsistent with their diplomatic or consular status".
The Russian Embassy in London added in its 'lame duck' memed tweet: "Everybody, including the American people, will be glad to see the last of this hapless administration."
According to one US official there are a total of about 100 Russian spies in the US, so about one third of them are being ejected.
The Kremlin accused the US of an "aggressive foreign policy" and behaving "like a bull in a china shop".
Kremlin spokesman Dmitri Peskov said: "There is no alternative here to the principle of reciprocity. We will deliver significant discomfort to the US side in the same areas.
"We consider this decision and these sanctions unjustified and illegal under international law."
Maria Zakharova, the Russian foreign ministry's spokeswoman, denied reports about the school closure on Friday morning.
Lisa Monaco, Mr Obama's homeland security adviser, said: "These 35 individuals were basically collecting intelligence. They were intelligence officers operating here and using these compounds for intelligence collection.
"We are expelling those 35 intelligence officers and their families and shutting down that intelligence collection activity."
She added: "We are prepared for retaliatory steps the Russian government may take."
The Russian Embassy in Washington said a plane was being sent from Moscow to pick up those who had been expelled.
How could Russia respond?
Vladimir Putin has ruled out direct retaliation for now, but he also says Russia "reserves the right" to respond. Here are a number of options he and his advisers could be considering.
- Expel US diplomats. Sending American officials home would be a traditional tit-for-tat response more or less in line with the rules of international diplomacy. The Russians could up the ante by kicking out Ambassador John Tefft (the US has said it is not expelling Russia's ambassador), which would leave a key post for Donald Trump to fill when he takes power on January 20.
- Shut down US diplomatic compounds. The foreign ministry has denied plans to close the American School in Moscow, which is popular with expat families. However, it could close the Embassy holiday dacha at Serebryany Bor on the Moscow outskirts.
- Something else. Previous "asymmetric" responses to American moves have included banning US citizens from adopting Russian orphans and banning food imports from countries that sanctioned Russia over its annexation of Crimea.
- Do nothing. With Donald Trump entering the White House on January 20, the Kremlin could decide it is worth refraining from countermeasures as a goodwill gesture to the new president. Instead it may confine itself to insulting Tweets about Barack Obama.