NEW YORK -- U.S. President Donald Trump on Wednesday signed into law the Hong Kong Human Rights and Democracy Act, which passed Congress almost unanimously, but had been strongly opposed by Beijing.

"Today, I have signed into law S. 1838, the 'Hong Kong Human Rights and Democracy Act of 2019,'" the president said in a White House statement.

Trump had been hesitant about signing the bill, as trade talks with China were in the "final throes," as he described on Tuesday.

While telling reporters that the U.S. was "with" Hong Kong's pro-democracy parties, he quickly added that he also has a good relationship with Chinese President Xi Jinping, signaling that the Hong Kong bill and trade talks were connected.

The president chose to sign the bill into law before the country breaks for the Thanksgiving holiday on Thursday.

China has vowed to retaliate if the bill was made into law.

The law requires the U.S. to impose sanctions on Chinese officials responsible for alleged human rights violations, and also requires the State Department to annually review Hong Kong's special status, which awards it preferential trade treatment.

The U.S. Senate passed the act unanimously while the House of Representatives passed it 417-1.

Trump had the choice of signing or vetoing the bill. If he had taken no action, the bill would automatically have become law after ten days.