Russian opposition leader Alexei Navalny, left, embraces his wife Yulia at a courtroom in Kirov, Russia, on Thursday. Alexei Navalny, one of the Russian opposition’s leading figures, was convicted of embezzlement Thursday and sentenced to five years in prison.

KIROV, Russia — Russian opposition leader and Moscow mayoral candidate Alexei Navalny was convicted of embezzlement Thursday and sentenced to five years in prison, a harsh ruling his supporters called an obvious attempt to shut down a foe of President Vladimir Putin and intimidate other opposition activists.

In a surprise move, prosecutors later asked that he be kept free pending appeal, possibly reflecting an attempt to soothe public anger and to lend legitimacy to a mayoral race expected to be won by a Kremlin-backed politician.

Navalny, who rose to fame as an anti-corruption blogger before leading unprecedented protests that revealed the depths of anger against the Kremlin, was found guilty of heading a group that embezzled 16 million rubles ($500,000) worth of timber from a state-owned company in 2009.

Backers say he is innocent, calling the trial unfair and the evidence against him shoddy. The U.S. and EU both criticized the ruling within hours, arguing that the case appeared to be politically motivated.

Navalny had expected the ruling and protests were planned even before it was handed down, setting up a potential confrontation with police, who routinely crack down harshly on unsanctioned rallies. By early evening, several hundred protesters gathered outside Red Square, shouting “Freedom!” amid thick police cordons. Police detained some of the demonstrators, but didn’t immediately move to disperse the rally.

In court, the 37-year-old lawyer played with his smartphone for much of the nearly 3 ½-hour verdict reading. A post on his Twitter account after the sentence was announced appeared to encourage supporters to continue his work: “Oh, well. Don’t get bored without me. And, importantly, don’t be idle.”

Navalny handed the phone and his watch to his wife, Yulia, before bailiffs took custody of him and a co-defendant Pyotr Ofitserov, who was given a four-year sentence.

A leading face of the opposition, Navalny was a top leader of the wave of massive protest rallies that broke out in late 2011 after a national parliamentary election scarred by allegations of widespread fraud.

He first called the dominant United Russia party “the party of crooks and thieves,” a phrase that became a rallying cry for the nascent opposition to Putin. But the ruling comes as the opposition suffers under a wave of Kremlin attempts to snuff it out, including shutting down NGOs and prosecuting protesters.

Navalny had declared himself a candidate for this fall’s Moscow mayoral election, but his chief of staff, Leonid Volkov, told The Associated Press they agreed he would drop out of the race if he was sentenced to prison.

It was not immediately clear if Navalny would stay in the race after prosecutors’ request that he be freed. The Kremlin may think that his popularity isn’t broad enough to pose an electoral threat to the incumbent.

“We are deeply disappointed in the conviction of Alexei Navalny and Pyotr Ofitservov and the apparent political motivations in this trial,” he wrote on Facebook.

Catherine Ashton, foreign policy chief for the European Union, said she was concerned about the conviction and sentence, saying in a statement that the charges had not been substantiated during the trial.

“This outcome, given the procedural shortcomings, raises serious questions as to the state of the rule of law in Russia,” she said.

German Chancellor Angela Merkel’s spokesman, Steffen Seibert, said that “five years in prison seems disproportionately high, even against the background of the crime he was accused of.” Seibert added there were grounds for “doubts as to whether motives of criminal law were in the foreground at this trial.”

Russian news reports said Navalny was taken to a detention facility in Kirov immediately after the verdict. Several dozen Navalny supporters gathered outside the facility soon after the sentencing.

Navalny’s wife appeared composed after seeing her husband taken away in handcuffs, saying, “If someone hopes that Alexei’s investigations will cease, that’s wrong.”

The Russian stock market, sensitive to politically charged issues, dove within minutes of the verdict, with the main MICEX index dropping 1.4 percent before partly recovering.

The case stems from when Navalny worked as an unpaid adviser to the provincial governor in Kirov, about 760 kilometers (470 miles) east of Moscow. Prosecutors say he was part of a group that embezzled 16 million rubles’ ($500,000) worth of timber from state-owned company Kirovles.

The defense argued that Ofitserov’s company bought the timber from Kirovles for 14 million rubles and sold it on for 16 million rubles in a regular commercial deal. Navalny’s lawyers presented invoices proving the transactions.

The judge said he found the testimony of key prosecution witness Vyacheslav Opalev to be “trustworthy and consistent.” Opalev, who was the timber company’s general director, got a suspended sentence in an expedited trial in December after pleading guilty to conspiring with Navalny.

Navalny insists Opalev framed him out of revenge: Navalny had recommended that Opalev be fired and that officials investigate potential corruption in his company, which had incurred 200 million rubles ($6 million) in losses by the time Navalny arrived in the region.

Throughout the trial, the testimony of prosecution witnesses clashed with the core arguments of the indictment that claimed Navalny’s work in Kirov led to the embezzlement. None of the managers at Kirovles who appeared in court, except for Opalev, was able to confirm that Navalny defrauded the company.

Navalny had long said he expected to be convicted, and in a final blog post before leaving Moscow for Kirov, he downplayed his personal importance to the wider opposition.

“The most important thing is to muster up the strength, shake off laziness and do something. This doesn’t require any leadership as such,” he wrote.