WASHINGTON (Reuters) - U.S. President Donald Trump on Wednesday signed into law congressional legislation backing protesters in Hong Kong despite angry objections from Beijing, with which he is seeking a deal to end a damaging trade war.

The legislation, approved unanimously by the U.S. Senate and by all but one lawmaker in the House of Representatives last week, requires the State Department to certify, at least annually, that Hong Kong retains enough autonomy to justify favorable U.S. trading terms that have helped it maintain its position as a world financial center.

The law also threatens sanctions for human rights violations.

Congress passed a second bill, which Trump also signed, banning the export to the Hong Kong police of crowd-control munitions, such as teargas, pepper spray, rubber bullets and stun guns.

“I signed these bills out of respect for President Xi (Jinping), China, and the people of Hong Kong. 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,” Trump said in a statement.

At the heart of matter is Beijing’s promise to allow Hong Kong a “high degree of autonomy” for 50 years when it regained sovereignty over the city in 1997, a pledge that has formed the basis of the territory’s special status under U.S. law. Protesters say freedoms have been steadily eroded.

Trump had been vague about whether he would sign or veto the legislation, while trying to strike a deal with China on trade that he has made a top priority ahead of his 2020 re-election bid.

After Congress passed the bill, Trump’s aides debated whether the president’s endorsement could undermine efforts to reach an interim trade deal with China, and most of them ultimately recommended the signing to show support for the protesters, a person familiar with the matter said.

The decision was also influenced by the overwhelming majorities in the Senate and House in favor of the legislation, which was widely seen as making the bills veto-proof, as well as the landslide election victory in Hong Kong earlier this week of critics of Chinese rule, the person said, speaking on condition of anonymity.

If Trump had opted to use his veto, it could have been overridden by two-thirds votes in both the Senate and the House. The legislation would have automatically become law on Dec. 3 if Trump had opted to do nothing.

China has denounced the legislation as gross interference in its affairs and a violation of international law.

After the Senate passed the legislation, Beijing vowed counter-measures to safeguard its sovereignty and security.

TRADE TALKS

Last week, Trump boasted that he alone had prevented Beijing from crushing the demonstrations with a million soldiers, while adding that he had told President Xi that doing so would have “a tremendous negative impact” on trade talks.

Trump prompted questions about his commitment to protecting Hong Kong freedoms when he referred in August to its mass street protests as “riots” that were a matter for China to deal with.

Trump again referred to “riots” last week, but has also called on China to handle the issue humanely.

Trump’s statement on the bill signing indicated that he was doing so with reservations about portions of the legislation, saying “certain provisions of the Act would interfere with the exercise of the president’s constitutional authority to state the foreign policy of the United States.”

FILE PHOTO: An anti-government protester holds a tear gas canister during a protest in Hong Kong, China October 20, 2019. REUTERS/Tyrone Siu/File Photo

Presidents often push back against such congressional measures, especially when they seek to mandate the imposition of sanctions, and use their signing statements to reinforce that they have the executive power to act at their discretion on foreign policy matters.

The person familiar with the matter said by publicly expressing such reservations Trump could be trying to assure the Chinese that he will not act to implement the toughest measures unless they sharply intensify their crackdown in Hong Kong.

Many see the U.S. legislation as symbolic, but the bills’ provisions have the potential, if implemented, to upend relations between the United States and Hong Kong and change the territory’s status to that of any other Chinese city.

Analysts say any move to end Hong Kong’s special treatment could prove self-defeating for the United States, which has benefited from the business-friendly conditions in the territory. If Hong Kong becomes just another Chinese port, companies that rely on the territory’s role as a middleman or for trans-shipping would likely take their business elsewhere.

That said, the bills contain strong waivers that would allow the president to block their provisions on national-security and national-interest grounds.

According to the State Department, 85,000 U.S. citizens lived in Hong Kong in 2018 and more than 1,300 U.S. companies operate there, including nearly every major U.S. financial firm.

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