Navalny was sentenced to five years for embezzling timber from a state-owned company on Thursday after what Kremlin critics said was a politically-motivated trial.
But the day after his conviction, prosecutors unexpectedly asked for his release, saying that keeping him behind bars during the appeals process would deprive him of his right to run for office.
Navalny returned to Moscow on Saturday and told crowds of supporters that he would win the mayoral election on 8 September.
Hundreds of police blocked his supporters from reaching the platform of the Moscow railway station where his overnight train from Kirov arrived.
Speaking through a loudhailer, he thanked those who turned out for a large demonstration near the Kremlin protesting against his sentence on Thursday.
He told supporters: “I realize that if it wasn’t for you I wouldn’t be standing here for the next five years.
“You have destroyed a key privilege that the Kremlin has been trying to keep – that it is their alleged right to say to any person: ‘arrest him on the spot’.
“We are going to run in this election and we will win,” he added, as supporters shouted: “We are the power.”
Navalny is one of the most high-profile opponents to Mr Putin and the governing United Russia party. His description of United Russia as the “party of crooks and thieves” has become a signature phrase of the opposition.
Some analysts saw Navalny’s sudden release as a sign of conflict between different factions within the Kremlin about how to respond to his widespread popularity among the urban middle classes.