MOSCOW — As fireworks lit the skies over Sochi on Sunday evening at the closing ceremony of the 2014 Winter Olympics, Russian President Vladimir Putin had every reason to feel satisfied with his country's hosting of the multibillion-dollar games.
Despite predictions that the Olympics would be a security and public relations disaster for the Kremlin, the Sochi Olympics remained free of terrorist attacks and major protests, further boosting Mr. Putin's confidence as he seeks to burnish his image as a world leader.
The two-week-long winter sports event also triggered a rise in patriotism as Russia topped the medals table.
Even a "soul-destroying" defeat for Russia's ice hockey team to the United States played to the Kremlin's advantage when it reignited anti-U.S. sentiments that Mr. Putin has encouraged since his return to the presidency in 2012.
Russia's 3-2 loss to the United States provoked a protest outside the U.S. Embassy in Moscow and anger on state-run TV, where a presenter claimed that a secret deal between Olympic organizers and NBC News had guaranteed victory for the Americans.
"The game was played out to American norms — both in politics and sport — according to which the USA must always win," seethed Rossiya 1 TV presenter Dmitry Kiselev, whom Mr. Putin honored this month for his services to the state.
Accusations of massive Olympics-related corruption by opposition figures faded as the games got underway, and the nation was caught up in the excitement of a once-in-a-lifetime sporting event.
"Putin is in a very good place right now," said Moscow-based analyst Anna Arutunyan, author of "The Putin Mystique." "Even the whining about hotel rooms [at Sochi] is not really putting a dent in the fact that Russia is doing pretty well.
"As for corruption, nothing happened at a larger scale than it's been happening for years," she said. "Besides, he looks likely to make a few heads roll after Sochi, which will shore up more support."
Mr. Putin's confidence was on full display throughout the games. Although Russia's longtime leader appeared to make concessions to the West ahead of the Olympics when he freed several high-profile critics from penal colonies, court cases against activists and protesters opposed to his long rule continued.
Russia's only independent TV channel was effectively barred from the airwaves on the eve of the Olympics, tightening the Kremlin's control over national media, and no embarrassing protests of Russia's law against gays occurred.
The only shadow on the horizon for Mr. Putin was the deadly uprising in neighboring Ukraine that appeared to have deposed Kremlin ally Viktor Yanukovych. Mr. Putin has targeted the former Soviet republic as a key member of his ambitious Eurasian Union, which many see as an attempt to re-create a Soviet-style alliance in Eastern Europe and Central Asia.
Protests in Kiev, the Ukrainian capital, began in November after Mr. Yanukovych backed away from a planned association agreement with the European Union in favor of relations with Russia. Moscow promised to purchase $15 billion in Ukrainian government bonds in return for rejecting the EU deal.
But after months of protest culminated last week in deadly street fighting, Mr. Yanukovych fled to eastern Ukraine, his support base. In scenes likely to have sent a shiver through the Kremlin, protesters swarmed his lavish private residence.
With the success of Ukraine's protest movement, Kremlin critics predict that Mr. Putin, 61, could be the next authoritarian leader to be toppled by angry crowds.
"When the oil revenues run out in Russia, when it becomes clear that Putin cannot rule, the same thing will happen here," journalist Vladimir Gromov wrote in an article posted online by the opposition-friendly magazine Snob.
Analysts were less certain, however, that a Ukrainian-type scenario would be on the horizon for Mr. Putin, who rode out mass protests against his rule in 2011 and 2012.
"Putin handled his own uprising pretty well," said Ms. Arutunyan. "Unlike Yanukovych, he was consistent: Lenient at first by allowing the rallies, then once they got even slightly violent or once police provoked them into becoming violent, the government moved in with precision repressions, which demoralized the opposition."
Others suggest that Mr. Putin maintains strong support throughout Russia and a firm grip on national television.
"The majority of Russians still consider Putin to be a legitimate president," said independent political analyst Dmitry Oreshkin, a former member of the Kremlin's human rights council. "State media has portrayed the Ukrainian protesters as the work of traitors working for American money and so on.
"The violence in Kiev may have tarnished Putin's international image, as most people suspect he encouraged the authorities to try to put down the protests. But here in Russia, people have been distracted by the Olympics," he said.
As chants of "Russia! Russia!" rippled across the Sochi Olympic stadium Sunday, Mr. Putin could well afford himself a wry smile that played across his lips at the culmination of Winter Games on which he staked his reputation and emerged a winner.
"Russia proved to itself and the whole world that we are strong enough to do the impossible," said Deputy Prime Minister Dmitry Kozak, appointed by Mr. Putin to organize Russia's first Winter Olympics.