MOSCOW — President Vladimir V. Putin of Russia announced Friday that he would not retaliate against President Obama’s decision to expel Russian diplomats and impose new sanctions — only hours after his foreign minister recommended doing just that.

Mr. Putin, betting on improved relations with the next American president, said he would not eject 35 diplomats or close any diplomatic facilities, rejecting a tit-for-tat response to the actions taken on Thursday by the Obama administration.

The switch was remarkable, given that Russia’s foreign minister, Sergey V. Lavrov, had just recommended the retaliation in remarks broadcast live on national television. He called for punitive measures mirroring the ones imposed by the Obama administration, which accuses Russia of intimidating American diplomats and hacking institutions like the Democratic National Committee to influence the 2016 election.

The two countries have a long history of reciprocal expulsions, and Russian officials had been threatening to retaliate for days. Then Mr. Putin abruptly changed course.