Hong Kong’s top court has granted a bid by democracy activist Joshua Wong to appeal his prison sentence.

The surprise decision gives Wong and fellow activist Nathan Law one last chance to fight their prison terms for involvement in an unlawful assembly that sparked huge 2014 pro-democracy protests in the Chinese territory city. Wong is facing six months in prison and Law eight months if their appeals fail.

They were bailed last month after serving two months so they could apply for an appeal, which the court of final appeal approved.

The court scheduled their appeal hearing for January.

The 21-year-old Wong shot to stardom for his role helping spearhead the protests three years ago against Beijing’s decisions to restrict elections for the city’s top leader.

They were sentenced to prison in August after the justice secretary won a legal request to get the courts to overturn an earlier, more lenient sentence letting them avoid jail time. The move raised concerns that the city’s independent judiciary was being undermined — part of broader tensions over Beijing’s increasingly strained relationship with Hong Kong, which includes calls for independence on college campuses and football fans booing China’s national anthem.

Legal experts and the activists had not expected Tuesday’s decision. Wong said last week that there was a good chance he would go back to prison, either for this case or a separate one in which he still faces sentencing.

“There will be more occasions in the future when our group of young people will go to prison, but we will persist in keeping the faith and working together to fight for democracy,” Wong said in the interview.

Under the “one country, two systems” framework, Beijing promised to let Hong Kong maintain wide autonomy and civil liberties following its 1997 handover from Britain. Residents fear China’s communist leaders are backtracking on the pledge.