Russian protest leader Alexei Navalny, left, addresses his supporters after arriving from Kirov, with his wife Yulia standing nearby, at a railway station in Moscow, July 20, 2013. (GRIGORY DUKOR/REUTERS)

Hundreds of supporters gave Alexei Navalny a hero’s welcome Saturday as Russia’s most prominent opposition leader returned to Moscow the day after his unexpected release from custody in Kirov.

Navalny, who was sentenced Thursday to five years in prison on what many viewed as a politically motivated charge of embezzlement, immediately confirmed that he would run for mayor of Moscow in September despite the hurdles.

“We are going to run in this election, and we will win,” he said to a jubilant crowd at Moscow’s Yaroslavsky railway station. “Ahead of us is a big and difficult electoral campaign. Seven weeks of nonstop work, and that’s just the start.”

Navalny’s triumphant return home from Kirov, 500 miles northeast of Moscow, capped a tumultuous week for the 37-year-old anti-corruption crusader, who was led in handcuffs from a court Thursday only to be set free within hours pending an appeal. That process could continue at least until the end of August.

Russia’s state prosecutor has ruled that Navalny’s continued detention would violate his right to run in the election. However, Russia’s judiciary is not known for either independence or clemency, and many observers here interpret the abrupt turn of events as a sign of a rift among the ruling elite.

Political commentators have suggested that the authorities want Navalny to run in the election because they see him as having little chance of winning. The likely victor is Sergei Sobyanin, whom the Kremlin appointed to a five-year term as mayor in 2010. Since then, Russia has decided to make the office elected. Early last month, Sobyanin officially resigned, a maneuver that allowed President Vladimir Putin to appoint him as acting mayor until September.

The short preparation time before the election seemed designed to help Sobyanin prevail and go on to serve with a voter mandate.

Navalny has attributed his release to the spontaneous protests that erupted in Moscow and nearly two dozen other Russian cities after he was sentenced. “I would never have believed that I would be back here at Yaroslavsky station within two days,” he said Saturday. “I apologize that I did not believe in you more strongly.”

However, close associates of Navalny confessed they were puzzled by the prosecutor’s decision, which risked turning the activist into a political hero. Some speculated that the authorities had decided it was less dangerous to let him go free than to face criticism for jailing him before an appeal. It is widely expected that Navalny will be sent back to prison.

Riot police clad in black helmets and bulletproof vests took up positions at Yaroslavsky station and in the surrounding streets early Saturday as Muscovites hurried to catch trains to their country homes at the start of the weekend.

Up until the last moment, station officials declined to reveal the platform where the 9:43 a.m. overnight train from Kirov bearing Navalny and his wife, Yulia, would arrive. But neither the confusion nor police appeals to the crowds to disperse prevented hundreds of Navalny’s supporters, many bearing bouquets of white flowers — the color of the Russian opposition — from swarming onto the station concourse to meet their leader.

After stepping off the train, Navalny was handed a small bullhorn to address the crowd, and admirers pressed bouquets of flowers on his wife.

“I don’t know if Navalny is any good, but he is certainly better than what we’ve got now,” said Lyudmila, an employee at the Russian State Library who was waiting to meet a friend. She declined to give her second name, saying it was best in Russia to “live for the day” and stay out of politics.

“It might look strange, but there is a logic to all this,” she said of Navalny’s release. “They will let him compete at the election and then have a perfect excuse to get rid of him. . . . Everything is going according to plan.”