The new Hong Kong security law will be a "sword" hanging over the heads of those who endanger national security, with Beijing and city authorities working together to enforce it, China said Tuesday.

Official news agency Xinhua said President Xi Jinping signed the law into effect after all 163 members of China's top lawmaking body voted unanimously to adopt it, and include it in Hong Kong's mini-constitution.

Critics and western governments fear the law will stifle freedoms in the semi-autonomous city.

But Beijing and Hong Kong's government have insisted the law will only target a minority of people and will restore business confidence after a year of pro-democracy protests rocked the city.

Critics and western governments fear Hong Kong's security law will stifle freedoms in the semi-autonomous city
Critics and western governments fear Hong Kong's security law will stifle freedoms in the semi-autonomous city AFP / Anthony WALLACE

"For the small minority who endanger national security, this law will be a sword hanging over their heads," said China's main body for Hong Kong affairs.

But "for the vast majority of Hong Kong residents and foreigners in Hong Kong, this law is a guardian spirit that protects their freedoms," the Hong Kong and Macau Affairs Office said.

The statement added that the central and city governments would "jointly" ensure the law is implemented, and "usher in a turning point, for chaos to turn into governance".

Beijing's liaison office in Hong Kong said the implementation of the law "is a major improvement of one country, two systems", referring to the system of governance applied in Hong Kong.

It said "no one should underestimate the central government's determination to maintain Hong Kong's national security" or "underestimate the ability of the central and special agencies to enforce laws strictly".