China warned the United States on Thursday that it would take "firm countermeasures" 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.

On Wednesday, U.S. President Donald Trump signed into law congressional legislation that 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 Thursday, with hundreds of people, young and old, some draped in U.S flags, gathering in the heart of the city.

"I was confident Donald Trump would sign the law because we are fighting for universal freedom. Everyone globally should support that," said 25-year-old Jacky, who only gave his first name.

"But we do want to give thanks to those around the globe that support us, a small city like Hong Kong, we thank them for their attention."

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

It also threatens sanctions for human rights violations.

China summons U.S. ambassador

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 on Thursday 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.

WATCH: Activist Joshua Wong talks about protests, U.S. bill

Joshua Wong says this sends the right signal to the world about Hong Kong's unique status 0:47

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, Xu Xijin, the editor of China's Global Times tabloid, said on Twitter.

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

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.

Hong Kong police entered the Polytechnic University on Thursday after a nearly two-week siege that saw some of the worst clashes between protesters and security forces.

A pro-democracy protester sits beside a thank you note and an umbrella bearing patterns of the U.S. flag after President Donald Trump signed legislation requiring an annual review of freedoms in Hong Kong. (Nicolas Asfouri/AFP/Getty Images)

It was unclear whether any protesters remained on the campus as about 100 plainclothes police moved in to collect evidence and remove dangerous items such as petrol bombs. Police said any protesters found would receive medical treatment and arrests were not a priority, though they were seen brushing Molotov cocktails for fingerprints.

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.

Reuters witnesses at the university said garbage and abandoned sleeping bags, helmets and gas masks were strewn everywhere, but no protesters could be seen.

Police officers dust down Molotov cocktail bottles for fingerprints at the Hong Kong Polytechnic University on Thursday. (Anthony Kwan/Getty Images)

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 increasing exponentially in October and November as violence escalated.

Demonstrators are angry at police violence and what they see as Chinese meddling in the 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 has blamed foreign forces for fomenting the unrest, an allegation repeated on Thursday 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 spokesperson Geng Shuang, pressed on specifics of countermeasures planned by Beijing, declined to comment on a timeline or any measures.

"You better stay tuned, and follow up on this," he told reporters on Thursday. "What will come will come."

WATCH: See some of the crowds at the recent protest

Protesters urge world to follow suit after Americans' Thanksgiving gift despite anger from Beijing 0:35

Gao Feng, a spokesperson for China's Commerce Ministry, did not comment directly on whether the Hong Kong 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.

Trade between Hong Kong and the United States was estimated at $67.3 billion in 2018, with the United States running a $33.8-billion surplus, its biggest with any country or territory, the Office of the U.S. Trade Representative says.