Less than 24 hours after Alexei Navalny, corruption fighter and President Vladimir Putin’s fierce opponent, was handcuffed and led away to serve a five-year prison sentence, he was free again to run for mayor of Moscow. Guessing at the reasons for the turnaround has become the Moscow political community’s favorite game in recent days, showing that no one really understands the workings of the nation’s Byzantine government.

On July 18, Navalny and his friend, businessman Pyotr Ofitserov, were convicted of stealing about $500,000 worth of lumber from a state-owned company in Kirov, a city where Navalny once served as an unpaid adviser to the governor. The flimsiness of the charges, and the predetermined verdict, left little doubt that Navalny was being punished for his criticism of Putin’s regime.

The thousands of Russians who took to the streets to demand Navalny’s release could not have expected it to come so soon or in such a bizarre fashion. The same prosecutor who demanded a prison term for Navalny petitioned the court for his release. On July 19, after a court session in which both sides and the judge were in surreal agreement, Navalny was set free until his appeal is heard. That allows him to continue campaigning in the Moscow mayoral election, set for September 8.

There is a simple legal explanation for the reprieve. Technically, the judge’s decision to send Navalny directly to prison violated the Russian Criminal Procedure Code, which requires an appellate court to confirm the sentence in such cases. So the prosecutor’s move could be seen as an effort to correct the judge’s error. But since the entire trial was a farce, few people see Navalny’s unexpected liberation as a triumph of due process.

The independent daily Vedomosti reported on July 22, quoting a spokesman for incumbent mayor Sergei Sobyanin, that the mayor had “asked the country’s leadership to help free Navalny.” That falls in with the theory that Sobyanin is seeking a legitimate election victory so he can get in line for the nation’s top job once Putin decides to relinquish power.

“Imagine for a moment that Sobyanin wins a fair, unrigged election against Navalny,” wrote opposition activist Ksenia Sobchak in the magazine Snob. “He would become the only legitimate politician in Moscow and the entire nation.”

Another hypothesis is that the Navalny confusion reflects a continuing struggle between liberals and hardliners within Putin’s entourage. The liberals -- a relative term in this context -- want to keep up the appearance of democratic fairness, while the hardliners are in favor of straightforward repression and a police state. In Navalny’s case, the liberals are represented by Sobyanin, and the hardliners by Alexander Bastrykin, head of the Investigative Committee, Russia’s version of the FBI. Navalny has written in his blog that Bastrykin set up a company in the Czech republic and failed to declare it to the Russian authorities. Bastrykin ordered the investigation that led to Navalny’s conviction.

“We do not know how the intrigue will unfold but it is obvious that the system is in disarray,” Sobchak wrote.

Other theories are more outlandish. Yevgeny Fyodorov, a parliament deputy from Putin’s United Russia party, said that U.S. President Barack Obama had persuaded the Russian authorities to release Navalny. “Now Navalny can walk the streets and beat people up and nothing is going to happen to him, because he is guaranteed immunity by the United States,” Fedorov said.

Some commentators have suggested that Navalny was a Kremlin project from the start. “Has Navalny made a deal with the government from jail?” ultra-nationalist novelist Eduard Limonov wrote in the pro-Putin newspaper Izvestia. “This whole Navalny story is beginning to smell really bad.”

Whether there is any truth to any of the theories, Navalny appears to be gaining in popularity. The Comcon polling service reported that even before the prison sentence and the unexpected liberation, he was gaining momentum in the Moscow mayoral race. In the week of July 11-16, Navalny was in second place after the incumbent with 14.4 percent of the vote, up from 10.7 percent the week before. The day after his release, Navalny received a hero’s welcome in Moscow as hundreds of people turned out to meet his train.

“Theoretically, every day of exposure in debates and the media means an additional one or two percentage points for Navalny’s ratings,” political scientist Dmitri Oreshkin told the website Slon.ru. “In the end, Sobyanin will find himself in a bad situation in which he may have to struggle to get Navalny off the ballot before the election if he gets too popular in the capital. After the sentencing, public awareness of Navalny has increased sharply.”

A triumphant Navalny winning millions of votes in Moscow despite the best efforts of his persecutors and alleged puppeteers would make a fairytale ending worthy of a Hollywood movie. In reality, the five-year sentence still hangs over Navalny’s head, and his support is still too low to present a serious challenge to Sobyanin. The current turbulence plays into the 37-year-old opposition leader’s hands, but a quick victory is as unlikely for him as winning the lottery.

(Leonid Bershidsky, an editor and novelist, is Moscow correspondent for World View. Opinions expressed are his own.)

To contact the writer of this article: bershidsky@gmail.com.

To contact the editor responsible for this article: Mark Whitehouse at mwhitehouse1@bloomberg.net.