BEIJING -- Hong Kong leader Carrie Lam accused foreign critics on Wednesday of displaying "blatant double standards" over moves by Beijing to strengthen control over the semi-autonomous territory.

British Prime Minister Boris Johnson announced earlier that his country is ready to open the door to almost 3 million Hong Kong citizens if China enacts a national security law for the city.

Following talks with officials in Beijing, Lam said China has the same right as the U.S. and Britain to enact legislation protecting its national security and that foreign criticism and threats of sanctions could not be justified. She also said China was compelled to take the step at the national level because opposition in Hong Kong's own legislature and among government critics made it impossible to do so locally.

"I can only say that the international community and some of the foreign governments have been adopting blatant double standards in dealing with this matter and commenting on this matter," Lam said.

"It is within the legitimate jurisdiction of any country to enact laws to protect and safeguard national security. U.S.A. is no exception. U.K. is no exception," Lam said. "So why should they object, resist or even condemn and take their sanctions against Hong Kong and the People's Republic of China for taking similar actions?"

Johnson said in a column published online by the South China Morning Post, a Hong Kong newspaper, that the security law would curtail freedoms in Hong Kong and conflict with China's obligations under its agreement with the United Kingdom when it took back the former British colony in 1997.

"Many people in Hong Kong fear their way of life -- which China pledged to uphold -- is under threat," he wrote. "If China proceeds to justify their fears, then Britain could not in good conscience shrug our shoulders and walk away."

China shocked many of Hong Kong's 7.5 million people when it announced earlier this month that it will enact a national security law for the city, which was promised a high level of autonomy outside of foreign and defence affairs.

In Beijing, foreign ministry spokesperson Zhao Lijian reiterated China's stance that the agreement with the U.K., known as the Sino-British Joint Declaration, was essentially null and void.

"The U.K. has had no sovereignty, governance or supervision over Hong Kong since its return (to Chinese rule)," Zhao said at a daily briefing.

"Therefore, the British side has no right to cite the Sino-British Joint Declaration to make irresponsible remarks on Hong Kong affairs and interfere in China's internal affairs," Zhao said.

In her comments, Lam appeared to agree, saying she was operating under Hong Kong's Basic Law, its mini-constitution, despite critics saying China's legislature used highly dubious legal grounds to circumvent Hong Kong's legislature in moving forward with the security legislation.

An earlier push to pass security legislation was shelved after massive Hong Kong street protests against it in 2003. However, Beijing appeared to lose all patience after months of sometimes violent anti-government protests in Hong Kong last year that China said was an attempt to split the territory off from the rest of China.

The standing committee of China's National People's Congress could enact the law later this month or at the end of August, analysts have said.

About 350,000 Hong Kong citizens hold British National Overseas passports, a legacy of the colonial era, and 2.5 million others are eligible to apply for them, Johnson said in his column. Long lines have formed at DHL courier offices in the city since the announcement as people rush to apply for or renew their BNO passports.

Johnson, echoing earlier statements by Cabinet ministers, said that if China imposes a national security law, Britain would allow holders of the BNO passports to remain for 12 months on a renewable basis and would grant them the right to work, placing them on a possible path to U.K. citizenship.

"This would amount to one of the biggest changes in our visa system in British history," Johnson wrote, adding, "I hope it will not come to this."

BNO passport holders currently can stay in the U.K. for only up to six months.

The security legislation also met with stinging criticism from the United States. President Donald Trump and Secretary of State Mike Pompeo said last week that Hong Kong is no longer autonomous and will be stripped of its preferential trade and commercial status.

Separately on Wednesday, Hong Kong pro-democracy activist Joshua Wong called on leaders in Europe to oppose the national security law, saying it erodes the "one country, two systems" framework promised to the semi-autonomous Chinese territory.

Wong said that after U.S. President Donald Trump threatened to impose sanctions on Hong Kong last week, the momentum should be kept to build a "global alliance to stand with Hong Kong."