China blasted critics of Hong Kong's new national security law on Wednesday, after Western powers and the United Nations said it would further curtail freedoms in the city.

Hong Kong, a former colony of Britain before the 1997 handover back to China, on Tuesday passed a security law commonly referred to as Article 23 to punish five crimes after a fast-tracked legislative process.

British foreign minister David Cameron said it was a "rushed" process for a law that would "further damage the rights and freedoms enjoyed in the city".

And Australia's top diplomat Penny Wong on Wednesday warned her visiting Chinese counterpart Wang Yi in Canberra that the new law would "further erode rights and freedoms" and have implications far beyond China.

The United States, United Nations, European Union and Japan have also publicly spoken out against the law.

Beijing on Wednesday blasted all criticism of the law, with foreign ministry spokesman Lin Jian telling the press that "attacks and smears will never succeed and are doomed to fail".

"Security is a prerequisite for development, and the rule of law is the cornerstone of prosperity," Lin said.

Earlier China's de facto foreign ministry in Hong Kong blasted Britain as being "hypocritical and exercising double standards" in an apparent reference to its own national security laws.

It also expressed "strong disaffection and opposition" to the EU's position.

As part of Britain's handover agreement to China, Hong Kong was guaranteed certain freedoms, including judicial and legislative autonomy, for 50 years in a deal known as "one country, two systems".

The accord cemented the city's status as a world-class business hub, bolstered by a reliable judiciary and political freedoms distinct from the mainland.

But 2019's massive and at times violent democracy protests -- which saw hundreds of thousands of Hong Kongers take to the streets to call for more autonomy from Beijing's rule -- drew a swift response from authorities.

Beijing imposed a national security law on Hong Kong in 2020 focused on punishing four crimes -- secession, subversion, terrorism and collusion with foreign forces.

Since its enactment, nearly 300 people have been arrested under the law, while dozens of politicians, activists and other public figures have been jailed or forced into exile, and civil society has largely been silenced.

- 'Grave concern' -

The newly passed law, which punishes treason, insurrection, theft of state secrets and espionage, sabotage, and external interference, will work in tandem to plug up "gaps" left by Beijing's legislation, Hong Kong's leader John Lee has said.

The government has argued its creation was a "constitutional responsibility" as outlined under Article 23 of Hong Kong's mini-constitution, which has governed the city since the handover.

But Cameron said the fast-tracked legislation undermined the Sino-British Joint Declaration, an internationally binding agreement signed in 1984 in which China agreed to run Hong Kong under the "one country, two systems" principle.

"I urge the Hong Kong authorities to... uphold its high degree of autonomy and the rule of law and act in accordance with its international commitments and legal obligations," he said.

His statement also drew a rebuke from the Chinese embassy in Britain, which called it "a serious distortion of the facts".

The embassy said the law, which imposes life imprisonment for crimes related to treason and insurrection, "fully safeguards the rights and freedoms enjoyed by Hong Kong residents".

"We urge the UK to cease its baseless accusations... refrain from interfering in China's internal affairs under any pretext," it said.

US State Department spokesman Vedant Patel said Tuesday that the United States was "alarmed by the sweeping and what we interpret as vaguely defined provisions" in the law.

UN rights chief Volker Turk called the law and its "rushed" adoption "a regressive step for the protection of human rights".

The EU criticised not only the expected impact of the law on the city's freedoms overall, but specifically said it had the "potential to significantly affect the work of the European Union's office", European consulates and EU citizens in Hong Kong.

"This also raises questions about Hong Kong's long-term attractiveness as an international business hub," the EU said in a statement Tuesday.

Japan on Wednesday added to the chorus, saying it attached "great importance to upholding a free and open system and ensuring the democratic and stable development of Hong Kong.

Japan "reiterates its grave concern about the passage of (Hong Kong's national security law), which will further undermine the confidence in the "One Country, Two Systems" framework".