HONG KONG — A Hong Kong court on Friday temporarily reinstated a ban on wearing face masks that targeted antigovernment protesters, after an earlier ruling found the law unconstitutional in what had been a rare victory for pro-democracy activists.

The judgment on Friday was handed down just days after China’s top legislative body, the National People’s Congress, said that it would step in, if necessary, to overrule the city’s judiciary. The warning was seen as the most decisive move yet by Beijing to intervene in Hong Kong’s political crisis.

It also came just ahead of citywide district elections on Sunday that are being seen as a referendum on the protest movement.

The ruling, by Hong Kong’s High Court, said that the ban on facial coverings would be brought back for seven days to give the government an opportunity to apply for an appeal. The court said the ruling had been made “in view of the great public importance of the issues raised in this case, and the highly exceptional circumstances that Hong Kong is currently facing.”