China's imposition of a national security law in Hong Kong would constitute a breach of a bilateral treaty and Britain would not stand idly by, Prime Minister Boris Johnson warned Wednesday in his first public response toward China's contentious move to rein in the former British colony.

In an opinion piece published in the online edition of the South China Morning Post, Johnson said the law would curtail Hong Kong's freedom and erode its autonomy.

British Prime Minister Boris Johnson claps his hands outside 10 Downing Street during the weekly 'Clap for our Carers' applause for the NHS and key workers on the front line of the coronavirus (Covid-19) pandemic on 28 May, 2020 in London, England. (NurPhoto/Getty/Kyodo)

"If China proceeds, this would be in direct conflict with its obligations under the Joint Declaration, a legally binding treaty registered with the United Nations," Johnson said. "Britain would then have no choice but to uphold our profound ties of history and friendship with the people of Hong Kong."

He was referring to changing Britain's immigration rules for some 2.9 million Hong Kong people who are entitled the British National (Overseas) passports, which were issued to those born prior to the territory's handover to China on July 1, 1997, but without granting right of abode in Britain.

The passport holders would, instead of staying for six months under current visa-free access rules, be allowed to stay for a renewable period of 12 months and "be given further immigration rights, including the right to work, which could place them on a route to citizenship," Johnson said.

The law, set to prohibit acts and activities of separation, subversion, terrorism and external interference in local affairs, could justify Hong Kong people's fear of their way of life, which China had pledged to allow to be maintained, being threatened.

"If China proceeds to justify their fears, then Britain could not in good conscience shrug our shoulders and walk away; instead we will honor our obligations and provide an alternative," Johnson said. "I hope it will not come to this."

Other countries have also raised concerns over the legislation's effect on Hong Kong's rights and freedoms. U.S. President Donald Trump has said his administration will take steps to revoke preferential treatment of Hong Kong and sanction Chinese officials should the law pass.

Hong Kong leader Carrie Lam, again calling foreign countries' criticisms of Beijing's legislation "blatant double standards," said it is legitimate for any country to legislate on national security.

"U.S.A. is no exception, U.K. is no exception," Lam told reporters after meeting with state officials over the legislation in Beijing. "So why should they object, resist or even condemn and take sanctions against Hong Kong and the People's Republic of China for taking similar action?"

Referring to a surge in migration seekers, Lam said the Hong Kong people's confidence lies in the financial hub's strengths and competitive advantages and not "in what individual foreign governments have to say" about it.

Calling on foreign countries to further impose sanctions on China, 23-year-old activist Joshua Wong said Beijing's failure to honor the joint declaration should cast doubt over its commitment to honoring other treaties.

"I hope to let more people in Europe realize that it's not only about the tension between U.S. and China, it's about how China expands its authoritarian value not only in Hong Kong but also all over the world," Wong said at a Foreign Correspondents' Club of Japan event.