HONG KONG/BEIJING (Reuters) - China warned the United States on Thursday that it would take “firm counter measures” in response to U.S. legislation backing anti-government protesters in Hong Kong, and said attempts to interfere in the Chinese-ruled city were doomed to fail.

U.S. President Donald Trump on Wednesday signed into law congressional legislation which supported the protesters, despite angry objections from Beijing, with which he is seeking a deal to end a damaging trade war.

Protesters in Hong Kong responded by staging a “Thanksgiving” rally, with thousands, some draped in U.S. flags, gathering in the heart of the city.

“The rationale for us having this rally is to show our gratitude and thank the U.S Congress and also President Trump for passing the bill,” said 23-year-old Sunny Cheung, a member of the student group that lobbied for the legislation.

“We are really grateful about that and we really appreciate the effort made by Americans who support Hong Kong, who stand with Hong Kong, who do not choose to side with Beijing,” he said, urging other countries to pass similar legislation.

The law requires the State Department to certify, at least annually, that Hong Kong is autonomous enough to justify favorable U.S. trading terms that have helped it become a world financial center.

It also threatens sanctions for human rights violations.

The Chinese foreign ministry said the United States would shoulder the consequences of China’s countermeasures if it continued to “act arbitrarily” in regards to Hong Kong.

Chinese Vice Foreign Minister Le Yucheng summoned U.S. Ambassador Terry Branstad and demanded that Washington immediately stop interfering in China’s domestic affairs.

Hong Kong’s Beijing-backed government said the legislation sent the wrong signal to demonstrators and “clearly interfered” with the city’s internal affairs.

China is considering barring the drafters of the legislation, whose U.S. Senate sponsor is Florida Republican Marco Rubio, from entering mainland China as well as Hong Kong and Macau, Hu Xijin, the editor of China’s Global Times tabloid, said on Twitter.

‘SINISTER INTENTIONS’

More than 5,800 people have been arrested since the unrest broke out in June over a proposal to allow extraditions to mainland China, the numbers grew in October and November as violence escalated.

Demonstrators are angry at police violence and what they see as Chinese meddling in freedoms promised to Hong Kong when it returned to Chinese rule in 1997, such as an independent judiciary.

China says it is committed to the “one country, two systems” formula put in place at the handover, and blames foreign forces for fomenting the unrest, an allegation it repeated in response to the U.S. law.

“This so-called legislation will only strengthen the resolve of the Chinese people, including the Hong Kong people, and raise awareness of the sinister intentions and hegemonic nature of the U.S.,” the foreign ministry said. “The U.S. plot is doomed.”

Foreign ministry spokesman Geng Shuang declined to comment on any countermeasures planned by Beijing.

Slideshow ( 30 images )

“You better stay tuned, and follow up on this,” he said. “What will come will come.”

Gao Feng, a spokesman for China’s commerce ministry, did not comment directly on whether the law would affect trade talks, saying there were no new details of their progress to disclose. Some analysts say any move to end Hong Kong’s special treatment could harm the United States, which has benefited from business-friendly conditions in the territory.

LULL IN VIOLENCE

Anti-government protests have roiled the former British colony for six months, at times forcing businesses, government, schools and even the international airport to close.

Slideshow ( 30 images )

Hong Kong has enjoyed a rare lull in violence over the past week, with local elections on Sunday delivering a landslide victory to pro-democracy candidates.

Prominent activists Joshua Wong and Denise Ho addressed the rally on Thursday night, thanking frontline protesters for the passage of the bill. Crowds sang the protest anthem “Glory to Hong Kong”, waving their phone torches.

Several hundred people also gathered outside the Polytechnic University, which police entered after a nearly two-week siege.

“The situation in Poly U is still a disaster,” said 30-year-old Ng, dressed in black and wearing a surgical mask. “We are out to show we will never forget the Poly U incident.”

The university became a battleground in mid-November, when protesters barricaded themselves in and clashed with riot police in a hail of petrol bombs, water cannon and tear gas. About 1,100 people were arrested last week.

It was unclear whether any protesters remained on campus as about 100 plainclothes police moved in on Thursday morning to collect evidence and remove dangerous items such as petrol bombs.

Police said they found more than 3,000 molotov cocktails and hundreds of bottles of corrosive liquids.

“The operation is going to finish today,” said Assistant Commissioner of Police (Operations) Chow Yat-ming.

He urged any remaining protesters to seek medical treatment, saying arrests were not a priority, though police were seen brushing molotov cocktails for fingerprints earlier in the day.

(This story corrects editor’s name in paragraph 11.)