HONG KONG -- A Hong Kong court on Thursday ordered all 47 pro-democracy activists charged under a Beijing-imposed national security law to be kept in custody after the Department of Justice appealed an initial decision to grant 15 of them bail.

Thirty-one of the activists were denied bail outright, with the co-founder of the 2014 Occupy Central protest movement, Benny Tai, withdrawing his bail application after he was ordered held in custody in a separate case.

The next hearing in the case will be on May 31.

The activists, aged 23 to 64, were charged with conspiracy to commit subversion under the security law and detained on Sunday over their involvement in an unofficial primary election last year that authorities said was a plot to paralyze Hong Kong's government.

The mass charges against the activists were the most sweeping action taken against the city's pro-democracy camp since the national security law was implemented last June.

With the 47 remanded in custody, nearly all of Hong Kong's most prominent pro-democracy figures will now be in jail or in self-exile abroad amid an ongoing crackdown on dissent in the semi-autonomous Chinese city.

The 15 activists initially granted bail are to appear in court within 48 hours for a review of the decision.

Political party League of Social Democrats Chairman Avery Ng said after the hearing that the Department of Justice's appeal of the decision to grant bail to 15 of the defendants was "insidious" and "absurd, ridiculous and inhumane."

Ahead of the bail decisions, over a hundred supporters gathered outside the West Kowloon Court, chanting slogans such as "Liberate Hong Kong, revolution of our times," which the government has made illegal due to secessionist connotations. Others sang the protest anthem "Glory to Hong Kong."

Police gathered and hoisted a warning flag, telling protesters that they may be in breach of the national security law.

Bail proceedings for the activists began on Monday, often taking a full day and at times continuing into the early hours of the morning.

Under Hong Kong's common law system, defendants are usually granted bail for non-violent crimes. But the national security law removed the presumption of bail, with a clause saying it will not be granted unless the judge has sufficient grounds to believe defendants "will not continue to commit acts endangering national security."

The 47 are part of a broader group of 55 activists who were arrested in January for their role in the primary elections. Eight of them were not charged on Sunday.

The primary was aimed at determining the strongest candidates to field for a Legislative Council election that would give the pro-democracy camp the best chance to gain a legislative majority. The government later postponed the election, citing public health risks from the coronavirus.

If the pro-democracy camp had won a majority, at least some members of the camp had plans to vote down major bills which would eventually force Hong Kong leader Carrie Lam to resign. Authorities said the activists' participation in the primary was part of a plan to paralyze the city's legislature and subvert state power.

The national security law criminalizes secession, subversion, collusion with foreign forces to intervene in the city's affairs as well as terrorism. Serious offenders could face life imprisonment.

Prominent pro-democracy advocate Joshua Wong, who is currently serving a 13 1/2-month jail sentence on protest-related charges, and former Democratic Party Chairman Wu Chi-wai were among the activists charged this week.

The case has drawn international scrutiny, with advocacy groups and politicians condemning the charges. U.K. Foreign Secretary Dominic Raab earlier called the charges "deeply disturbing" and said the national security law was being used to eliminate political dissent.

Correction:

This story has been corrected to show that one defendant withdrew his bail application ahead of the decision.