“If the U.S. continues to make the wrong moves, China will be taking strong countermeasures for sure,” a spokesman for China’s Foreign Ministry, Geng Shuang, told reporters in Beijing on Thursday.

Without naming Mr. Trump, he urged the United States to “stop its wrongdoing before it’s too late, prevent this act from becoming law” and “immediately stop interfering in Hong Kong affairs and China’s internal affairs.”

China often issues angry criticisms of Washington with little follow up. And Chinese negotiators have also pushed to isolate the trade talks from a range of security-related matters, including the Trump administration’s crackdown on the Chinese telecom firm Huawei and the American sale of fighter jets to Taiwan.

“What has been surprising to me throughout the trade negotiations has been the degree of China’s willingness to compartmentalize issues,” said Evan S. Medeiros, another top China aide in the Obama White House.

“Obviously the Chinese don’t want the president to sign it. But are they going to be willing to blow up the trade deal to do so?” added Mr. Medeiros, now a professor at Georgetown University’s Walsh School of Foreign Service. “I don’t think they will, in large part because they understand he has a lot of discretion with this particular bill.”

In June, Mr. Trump told President Xi Jinping of China that he would not publicly back the protesters as long as trade talks were progressing. Administration officials have said that they have some reservations about striking a trade deal with China at a time when violence in Hong Kong could worsen, but that it is not the main impediment to reaching an agreement.

Congress acted on the measure, which had been stalled, after the riot police challenged student activists on campuses for the first time this month. Mr. Trump has said he hopes the crisis “works out for everybody,” and has suggested that the matter is an internal affair for China to resolve.