China threatened retaliation against Washington on Thursday after US President Donald Trump signed legislation supporting Hong Kong pro-democracy protesters, just as the world's top two economies edge towards a trade truce.

Trump signed the legislation under heavy pressure from Congress, where it attracted rare bipartisan support, and in a statement spoke of his "respect" for Chinese President Xi Jinping, calling for both sides to "amicably settle their differences".

But Beijing lashed out furiously, summoning the US ambassador, threatening unspecified "firm countermeasures" and warning Washington not to implement the legislation.

"The nature of this is extremely abominable, and harbours absolutely sinister intentions," the Chinese foreign ministry said in a statement.

Pro-democracy protesters chant slogans in a shopping mall in Hong Kong on November 27, 2019 Pro-democracy protesters chant slogans in a shopping mall in Hong Kong on November 27, 2019 Photo: AFP / DALE DE LA REY

"China strongly urges the US side to correct mistakes and change course," the ministry added later.

In Hong Kong, the government expressed "extreme regret" after Trump signed the legislation requiring an annual review of freedoms in Hong Kong and banning the sale of crowd control equipment.

A 'Statue of Democracy' at the Hong Kong Polytechnic University, where police surrounded the premises while protesters were barricaded inside A 'Statue of Democracy' at the Hong Kong Polytechnic University, where police surrounded the premises while protesters were barricaded inside Photo: AFP / Anthony WALLACE

"The two acts are obviously interfering in Hong Kong's internal affairs," the city government said in a statement, warning the move would "send the wrong message to the protesters".

US President Donald Trump at a campaign rally in Sunrise, Florida US President Donald Trump at a campaign rally in Sunrise, Florida Photo: AFP / MANDEL NGAN

Hong Kongers have protested in huge numbers over the last six months, fuelled by years of growing fears that authoritarian China is stamping out the city's liberties.

The territory's Beijing-backed leaders have offered few concessions and police have cracked down hard on protesters in increasingly violent confrontations.

IMAGESHong Kong police look for petrol bombs and other dangerous materials after entering a ransacked university campus where authorities faced off for days with barricaded pro-democracy protesters. IMAGESHong Kong police look for petrol bombs and other dangerous materials after entering a ransacked university campus where authorities faced off for days with barricaded pro-democracy protesters. Photo: AFPTV / Daniel SUEN

More than 5,800 people have been arrested and nearly 1,000 charged, with detentions skyrocketing in the last two months.

On Thursday, police entered the campus of the Hong Kong Polytechnic University, to which they have laid siege for days.

Most protesters have now left, some of them arrested and beaten as they tried to flee, and police were collecting evidence including Molotov cocktails and archery bows at the ransacked site.

Clashes between Hong Kong police and protesters have become increasingly violent Clashes between Hong Kong police and protesters have become increasingly violent Photo: AFP / NICOLAS ASFOURI

The violence has done little to dampen public support though, with pro-democracy candidates winning a landslide victory in local council elections over the weekend.

The Hong Kong Human Rights and Democracy Act requires the US president to annually review the city's favourable trade status and threatens to revoke it if the semi-autonomous territory's freedoms are quashed.

Trump also signed legislation banning the sale of tear gas, rubber bullets and other equipment used by Hong Kong security forces in putting down the protests.

Hong Kong activists said the move would help build international support.

Sunny Cheung, a student who testified before Congress in support of the legislation, told AFP it would give "Hong Kong people timely leverage to press Hong Kong and Beijing further on democratic reform".

On Thursday evening, several thousand people attended an evening Thanksgiving rally, waving US flags as the American national anthem played.

Keith Fong, president of Baptist University students union, told AFP he was grateful to Trump for signing the legislation.

"America didn't have any duty to do this," he said, shrugging off concerns about the city being caught in the wider US-China trade war.

"Hong Kong has been living amid great power struggles since it opened as a commercial port. This is a good time for us to leverage this role to gain more support around the world."

It was the first significant protest after an election lull, but organiser Ventus Lau said he expected demonstrations would soon ramp up again.

There had been speculation Trump could veto the bill to protect his chances of securing a China trade deal as his re-election campaign ramps up.

But he would have faced the humiliating possibility of Congress coming together to override his veto with a two-thirds majority.

His decision was welcomed even by his fiercest domestic opponents, including Democratic House Speaker Nancy Pelosi.