HONG KONG — Three prominent young leaders of Hong Kong’s democracy movement were sentenced Thursday to six to eight months in prison, a severe setback for the semiautonomous Chinese city in its struggle for greater political freedom under Communist Party rule.

Joshua Wong, the face of huge street demonstrations in 2014 for freer elections of Hong Kong’s leader, was sentenced to six months in prison. Two fellow protest leaders, Nathan Law and Alex Chow, were given eight and seven months, respectively.

The sentences risked casting the three young men as Hong Kong’s first prisoners of conscience, undermining the city’s reputation as a haven of civil liberties with special status in China.

Originally sentenced to community service and a suspended jail term, the three activists were given the prison sentences by an appeals court after the Beijing-backed local government successfully pushed for harsher punishments. By law, the prison terms left them ineligible for public office for five years.

“The government wanted to stop us from running in elections, and directly suppress our movement,” Mr. Wong said in an interview before the decision on Thursday afternoon. “There’s no longer rule of law in Hong Kong, it’s rule by law.”

After the sentences were announced, Mr. Wong posted a series of defiant messages on Twitter saying that he would not give up his fight for democracy. All three were taken into custody immediately.

They can silence protests, remove us from the legislature and lock us up. But they will not win the hearts and minds of Hongkongers.

They all intend to appeal their sentences, according to Lester Shum, a fellow protest leader, who read a statement outside the court.

In a statement issued Thursday night, the Hong Kong Department of Justice defended its appeal for tougher sentencing as its legal right, adding that the three protest leaders “were convicted not because they exercised their civil liberties, but because their conduct during the protest contravened the law.”

Suzanne Pepper, a Hong Kong-based scholar of Chinese politics, said the new sentences were “part of a larger pushback by Beijing against Hong Kong’s democracy movement.”

“It’s a two-part strategy aimed at targeting the leaders, making an example of them, showing the cost for all who might want to follow in their footsteps and offering rewards to all who settle down,” she said in an email. “Sort of a combined carrots-and-sticks strategy, plus ‘killing the chicken to frighten the monkeys.’”

The protests and the police response cascaded into weeks of sit-ins, later known as the Umbrella Movement, that paralyzed several major streets across Hong Kong but failed to win the protesters any political concessions.

The former British colony returned to Chinese rule 20 years ago under a “one country, two systems” governing principle that promised a high degree of autonomy. Yet the public’s trust in the political firewall has eroded as the Chinese authorities appear ever more assertive in exercising their will in the city.

A lower court had previously avoided deterrent punishment for Mr. Wong, Mr. Law and Mr. Chow, citing their “genuine wish to express their political ideals and concerns for society.” But prosecutors argued that lenient sentences would send the wrong message as they pursued legal action against even more participants and leaders of the largely peaceful protests.

Video

In 2014, Joshua Wong was at the forefront of a student movement for democracy in Hong Kong.Published OnOct. 1, 2014

The three judges at the appeals court were in agreement that tougher sentences were warranted in order to deter unlawful protests.

“The freedom of assembly is never absolute,” Wally Yeung, a vice president of the Court of Appeal, wrote in the judgment, adding that the court must uphold the importance of public order even though “sentencing ambitious, idealistic young people to immediate imprisonment” was not a judgment he made “readily.”

The Hong Kong police arrested more than 900 people during the demonstrations in 2014, when thousands of protesters shut down streets in several major business districts for almost three months. The government has brought charges against fewer than one-tenth of them, and those found guilty have been mostly sentenced to probation or community service.

The sentencing of the three protest leaders capped an emotional week for the city’s embattled democracy activists, with one Democratic Party member being accused on Tuesday of falsifying an account of abduction and torture by Chinese agents.

Those protesters included members of the Demosisto party formed by Mr. Law and Mr. Wong last year. At a news conference on Tuesday, Mr. Law broke down in tears while expressing his support for them.

On Wednesday, the night before the sentencing, others wept for Mr. Law, as he and Mr. Wong addressed hundreds of supporters gathered outside the square where they protested in 2014.

“Do not give up on Hong Kong. We can still win,” said Mr. Wong, wearing the same T-shirt he did nearly three years ago when he, then 17, climbed over a fence into the square. “I don’t know what will happen in the next six to 12 months, but I hope in 2018, when we are freed, we’ll see a Hong Kong with hope.”

A version of this article appears in print on , on Page A7 of the New York edition with the headline: Three Young Democracy Advocates in Hong Kong Are Sentenced to Prison. Order Reprints | Today’s Paper | Subscribe