HONG KONG — Beijing on Thursday lambasted President Donald Trump for backing legislation supporting human rights in Hong Kong, condemning the U.S. for its “stark hegemonic acts” and for interfering in the semiautonomous region’s affairs.

In response to the U.S. move, activists chanted “Stand with Hong Kong” and "Save Us," and urged the world to follow in America’s footsteps. Joshua Wong, a prominent activist who was among democracy supporters who lobbied for the new U.S. laws, praised them as a “remarkable achievement,” with human rights triumphing over crucial U.S.-China trade talks.

On Wednesday, Trump signed two bills into law. One prescribes economic sanctions on Hong Kong and Chinese officials found guilty of human rights abuses. The second bill bans the export of certain nonlethal munitions to the former British colony’s police.

A protester holds American flags during a demonstration in Hong Kong's financial district on Thursday. Kin Cheung / AP

“I signed these bills out of respect for President Xi, China, and the people of Hong Kong,” said Trump in a statement released by the White House. “They are being enacted in the hope that leaders and representatives of China and Hong Kong will be able to amicably settle their differences leading to long term peace and prosperity for all.”

China, which has been struggling to contain anti-government protests roiling Hong Kong for nearly six months, responded with a stream of angry replies.

“We urge the U.S. to not continue going down the wrong path, or China will take countermeasures, and the U.S. must bear all consequences,” the Chinese Foreign Ministry said in a statement.

The editor of the Global Times, a newspaper owned by the Chinese Communist Party, responded sarcastically to Trump’s message.

“Out of respect for President Trump, the U.S. and its people, China is considering [putting] the drafters of the Hong Kong Human Rights and Democracy Act on the no-entry list, barring them from entering Chinese mainland, Hong Kong and Macao,” Hu Xijin wrote in a post on Twitter.

Beijing’s liaison office in Hong Kong expressed “extreme anger” toward the U.S., and added that Hong Kong belongs to China and “the Chinese have the ability to deal with Hong Kong affairs.”

Hong Kong's government joined in, describing the bills’ passage as “unnecessary and unwarranted,” and warning that they would strike a blow against the “relations and common interests” of Hong Kong and the U.S.

Thousands, many waving American flags, gathered in Hong Kong's financial district to celebrate the bills signed by Trump.

“This rally is to show our gratitude to America and also President Trump for passing the bill,” said Sunny Cheung, the rally organizer.

Student David So agreed.

“I think it’s a happy news,” he said. “It’s an international recognition on today’s Hong Kong situation.”

“Ultimately it’s up to us. The bills have their deterrent effects but Hong Kongers are the real ones who fight on,” he added.

Millions of Hong Kongers initially took to the streets over the summer to protest a controversial extradition bill that many feared would extend Beijing’s control over the city. The amorphous movement has developed wider demands for greater democracy, such as establishing an independent commission of inquiry into police brutality and universal suffrage.

So the U.S. bills are a major boost for the protesters, according to Joseph Cheng, a political science professor at City University of Hong Kong.

“Certainly, a lot of us are quite helpless in front of Beijing and Carrie Lam's administration and the police,” he said, referring to the territory's beleaguered chief executive. “I think what worries the Chinese authorities [is] the turning tide in the public opinion of the United States and the Western world.”