Editor's note: Daniel Treisman is a professor of political science at the University of California, Los Angeles, and author of "The Return: Russia's Journey from Gorbachev to Medvedev."
(CNN) -- As Russian President Vladimir Putin opens the Winter Olympics in Sochi on February 7, there will be relief hidden behind his characteristically guarded smile. For Putin, the past two years have witnessed a remarkable recovery.
Two years ago, Putin seemed to be on the ropes. Tens of thousands of Muscovites were flooding central squares to protest a parliamentary election they said had been tarnished by massive fraud. His approval ratings were in free fall, having dropped 15 points since December 2010, according to polls from Moscow's Levada Center.
Internationally, Putin was also on the defensive. He appeared to have isolated himself by backing the wrong horse in Syria's civil war. As rebels closed in on the Damascus suburbs, many observers thought Syrian President Bashar al-Assad, whom Putin supported, would soon be swept from power. If so, Russia stood to lose its only Mediterranean military outpost, the naval station it leased at Tartus.
The European Union, alarmed at the continent's dependence on Russian gas, had raided offices of the Russian company Gazprom in Germany and the Czech Republic and was planning further investigations. When built, a projected EU- and U.S.-supported Nabucco pipeline threatened to pump gas from Azerbaijan to Vienna, undercutting Russian supplies.
Not since the height of the global financial crisis had Putin seemed so embattled.
Today, things look quite different. Over the following year, the Moscow protests died away. Putin's ratings stabilized in the low 60s, a level many Western leaders would envy. With a mixture of new repressive laws, prosecutions and co-optation tactics, the Kremlin managed to box in and divide its domestic critics.
So confident did Putin feel by mid-2013 that he could, without losing sleep, allow the opposition activist Alexei Navalny to run for mayor of Moscow (he lost, though with an impressive 27%) and pardon his nemesis, the imprisoned former oligarch Mikhail Khodorkovsky, allowing him to leave for Switzerland.
Putin's star has also risen on the international stage. In September, he persuaded al-Assad to pledge to give up his chemical weapons, saving President Barack Obama from a military intervention the U.S. leader clearly dreaded. Al-Assad looks more secure today than he has since protests against his rule began.
By granting asylum to the NSA leaker Edward Snowden, Putin managed -- ironically, given Russia's own record of secrecy and spying -- to place himself on the side of a global movement for greater transparency and respect for citizens' privacy. One example: The New York Times, in a recent editorial, called Snowden's revelations "a great service" and urged Obama to end Snowden's vilification and offer him "a plea bargain or some form of clemency."
In a showdown with the EU over the future of Ukraine in November, Putin again came out on top, persuading Ukrainian President Viktor Yanukovych to reject a trade deal with Europe to which Brussels had committed its prestige. Instead, Yanukovych pledged to deepen his country's trade ties with Russia, prompting furious protests from pro-Europe Ukrainians. As for Gazprom, its sales of gas to Europe rose by 16% in 2013 to a record high. The Nabucco pipeline failed to line up committed gas supplies. According to one of the consortium's partners, as of June the project was "over."
Most of these successes are temporary, and time is not on the Kremlin's side. Fighting continues to rage in Syria, and the destruction of al-Assad's chemical weapons has been painfully slow. Ukraine will sooner or later integrate with Europe. Yanukovych is struggling to stay in power as violence flares nightly in central Kiev. Gazprom's buoyant sales reflected an unusually cold winter in Europe.
At home, the frustrations that fueled the demonstrations two years ago have not gone away, just lost a focus. A major economic deterioration could prompt a new, potentially more consequential wave of protests. Russia's growth rate has been falling steadily, reaching just 1.4% by the end of 2013, the lowest rate of Putin's years as President. And the Kremlin has no serious strategy to restart the economic engines.
For now, Putin still has reason to feel confident. Even Sochi, which could have turned into a political disaster, might well pass off positively for the Kremlin. The advance bad press has lowered expectations so much that the Games will seem something of a success if they merely take place without the stadium collapsing or terrorists exploding bombs in Sochi itself.
The de facto boycott by Western leaders over Russian intolerance toward gays will probably buy Putin a little support at home since most Russians share his discomfort with "nontraditional lifestyles" and do not like outsiders telling them what to do. In a recent poll, 73% agreed the state should ban public displays of homosexuality.
What explains this turnaround?
Putin has benefited more from luck than skill. Even without new repressive measures, the wave of demonstrations was bound to subside, following the natural ebb and flow of protest movements. Those that climax without producing leader turnover tend to lose momentum, though some might reignite months or years later.
In international affairs, Putin profited from the mistakes of the West. Obama, having backed himself into a corner with talk of "red lines" and facing a humiliating veto in Congress, had to smile and accept help on Syria from the leader he had recently taunted for his "slouch." The European Union overplayed its hand in Ukraine, insisting on terms that Yanukovich thought would damage him politically. Putin, offering a bailout with fewer visible strings attached, walked away with the Ukrainian leader's agreement.
One may debate whether the real mistake in the Snowden case was the extent of U.S. spying or the lax security that allowed Snowden to expose it. Either way, it was a U.S. blunder, which landed unexpectedly in Putin's lap.
At some point, Putin's luck is bound to run out. Both at home and abroad, political challenges loom in 2014. Still, as he prepares to greet and congratulate the Olympic athletes, Russia's President is on a roll.
Follow us on Twitter @CNNOpinion.
Join us on Facebook/CNNOpinion.
The opinions expressed in this commentary are solely those of Daniel Treisman.