KIROV, Russia Russia unexpectedly freed opposition leader Alexei Navalny on bail on Friday, bending to the will of thousands of protesters who denounced his five-year jail sentence as a crude attempt by President Vladimir Putin to silence him.
Putin's spokesman called the protesters "mobs" and warned that the rallies were illegal.
In a highly unusual ruling that points to Kremlin uncertainty over how to handle Navalny's case, a judge approved the prosecution request to free him pending his appeal so that he can run in a Moscow mayor election on September 8.
The anti-corruption blogger will be unable to leave Moscow but hailed the decision, a day after he was convicted of theft, as a victory for people power.
Experts said it was unprecedented for the prosecution to seek bail on such terms after sentencing.
"I am very grateful to all the people who supported us, all the people who went to (protest in Moscow's) Manezh Square and other squares," the 37-year-old said, rushing across the court to hug his wife after he was let out of a glass courtroom cage.
The judge's decision was greeted by applause in the court in Kirov, 900 km (550 miles) northeast of Moscow. Under Russian law, he has 10 days to file an appeal and then the court has to decide whether to hear that appeal in 30 days.
"We understand perfectly well what has happened now. It's an absolutely unique phenomenon in Russian justice," Navalny said.
People poured onto the streets of Russian cities to protest on Thursday evening after Navalny was convicted of stealing at least 16 million roubles ($494,000) from a timber firm when he was advising the Kirov regional governor in 2009.
More than 200 people were detained although the rallies were peaceful, with demonstrators chanting "Shame!", "Freedom!" and "Putin is a thief!"
In Moscow, drivers honked their horns in support as they drove past at least 3,000 demonstrators a few hundred metres from the Kremlin's red brick walls.
Navalny says his trial was politically motivated and intended to sideline him as a threat to Putin, even though his support is limited outside the cities and opinion polls show the president is still Russia's most popular politician.
Putin has not commented on the verdict against Navalny or his release from custody. Putin's spokesman, Dmitry Peskov, said the rallies were illegal because they were held without approval from the authorities.
"There is no doubt that it is impossible to condone such mobs, and one can only hope that in the future everything will be done within the framework of the law," Peskov told reporters.
The trial was a matter for the courts "and has nothing to do with the president," he said.
Navalny led anti-Putin protests in Moscow which attracted tens of thousands of people at their peak last year. But they did not take off in the provinces, Putin's traditional power base, and faded after the former KGB spy was elected to a six-year third term as president in March 2012.
The sight of protesters so close to the heart of power on Thursday may have unsettled the Kremlin, and Friday's bail decision could be a political manoeuvre to head off new protests that would worry investors.
The judge ruled that keeping him in detention put "him on an unequal footing against other candidates (in the mayoral election) and restricts his right to be elected".
The current mayor, Sergei Sobyanin, a close Putin ally, said he would prefer to be challenged by Navalny, who opinion polls show is trailing him by a long way.
A source close to the mayor said Sobyanin, who is tipped as a potential prime minister, was worried the removal of Navalny as a candidate would tarnish his expected victory.
Some analysts said the Kremlin, and the business and security community around it, looked divided over Navalny.
"There really is a split in the elite and it seems there will be no peaceful outcome," said political scientist Ella Paneyakh, who described the bail request by the state prosecution as unprecedented.
SPLITS IN THE KREMLIN?
Putin is under no immediate political threat from Navalny, or any other opposition figure, but his grip on power has long depended on maintaining calm and a balance of forces between the conservatives and more liberal forces around him.
Cracks in the facade of unity have appeared, particularly over the removal from government of Vladislav Surkov, Putin's former political strategist, in May. Surkov had fallen foul of more hawkish Kremlin allies who are in the ascendancy as Putin takes a tough line against opponents after last year's protests.
"I think the split at the top of the Kremlin pyramid has now become absolutely obvious," said Alexei Roshchin, a veteran campaign adviser and sociologist.
"Before our very eyes the Navalny case is acting as a catalyst for the split in the elites."
Members of the Kremlin human rights council on Friday supported calls for an independent review of the case against Navalny, the Interfax news agency cited the advisory body's head, Mikhail Fedotov, as saying.
The United States and European Union voiced concern over Navalny's conviction, saying it raised questions about the rule of law and Russia's treatment of Putin's opponents.
"The fact that they were released under specific conditions is something that we can welcome, but how the whole case has been handled simply underlines our concerns," a spokeswoman for EU foreign policy chief Catherine Ashton said.
While it makes it easier for him to stay in the mayoral race, there is no indication Navalny's release from custody will affect the court's ruling on his planned appeal.
The acquittal rate in Russia is about half a percent, or one in 200, and has declined in recent years, said Pavel Chikov, a human rights lawyer and head of legal rights group Agora.
(Additional reporting by Alexei Anishchuk, Denis Dyomkin, Maria Tsvetkova and Steve Gutterman, Writing by Timothy Heritage, Editing by Elizabeth Piper and Angus MacSwan)