Alexei Navalny says the court's decision to release him ahead of an appeal is a "unique phenomenon".

Reuters: Sergei Karpukhin

A court in northern Russia has ordered the release of protest leader Alexei Navalny pending the appeal against his five-year sentence on embezzlement charges.

The court ruled that keeping Navalny - one of president Vladimir Putin's biggest critics - in custody would deprive him of his right to stand in mayoral elections in Moscow on September 8.

Navalny had been accepted as a registered candidate for the polls earlier this week.

The 37-year-old and his co-accused Pyotr Ofitserov were immediately released in court and Navalny embraced his wife Yulia.

"This is a major surprise," a jubilant Navalny said after being released from the glass-fronted defendant's cage.

"What happened now is a completely unique phenomenon in the system of Russian justice."

The court ruling came after prosecutors, in a surprise move, asked the court to release Navalny from custody until the appeals process is over, at which time his sentence would come into full force if his conviction is upheld.

It was not entirely clear what had motivated the prosecutors to make the appeal, which came as thousands of people rallied on the streets of Moscow in support of Navalny.

Navalny's aides had said on Thursday that he would pull out of the mayoral race after his conviction and jailing, but the charismatic protest leader said he would now consider is options after returning to Moscow.

He said he could still stand as a candidate or urge supporters to boycott the race.

His release from custody on Friday is conditional on him staying in Moscow, his city of residence, pending his appeal.