A worker watches as shipping containers are loaded onto a ship at a port in Qingdao in eastern China's Shandong province, on Aug. 8. (AP)

China sharpened its rhetoric over the Trump administration’s efforts to investigate its trade practices, vowing on Thursday to use “all means necessary” to defend the country and its companies.

Although analysts don’t believe a trade war between the world’s two largest economies is imminent, China’s harsh words underline a recent fraying of the relationship between Beijing and Washington over trade and North Korea.

On Wednesday, China’s Foreign Ministry demanded that the United States “immediately” withdraw unilateral sanctions imposed on several Chinese companies and individuals accused of illegally trading with the Pyongyang regime.

President Trump initially said he would set aside trade disputes with China to gain Beijing’s cooperation in reining in North Korea, but he reversed course this month by calling for a probe into the theft of intellectual property by Chinese companies.

Experts say the Trump administration may be coming to terms with the limits of Beijing’s willingness to put pressure on Pyongyang and wants to demonstrate that it is taking steps to bring down the trade deficit, a key campaign promise.

On Monday, the Chinese Commerce Ministry called the Trump administration’s intellectual property investigation “irresponsible” and “protectionist,” arguing that it ignored the rules of the World Trade Organization.

On Thursday, it upped the ante, saying the decision had “poured cold water” on efforts to improve bilateral trade relations.

“We are strongly discontented with this unilateralism and protectionism and will take all means necessary to resolutely defend the legitimate rights and interests of the Chinese side and Chinese enterprises,” Gao Feng, a spokesman for the Commerce Ministry, said at a news conference, calling the Trump administration move a “violation” of the international trade system.

Nevertheless, experts think a trade war remains an unlikely and distant prospect, mainly because it would be damaging to both sides.

“If Trump initiates sanctions against China, especially the Section 301 investigation, it would be like killing 10,000 enemies at the cost of losing 8,000 of its own troops,” said Wei Jianguo, vice chairman of the China Center for International Economic Exchanges and a former vice commerce minister. “It’s really unnecessary, and it would cause grave losses to both sides.”

Although the United States runs a $310 billion trade deficit with China, Wei said American exports to China were substantial and growing fast.

The inquiry into the theft of U.S. intellectual property could take months to conclude. In the meantime, China will want to keep relations on an even keel, ahead of a key Communist Party congress in the fall and ahead of a planned visit by Trump later this year.

Shortly before he left the White House, Trump strategist Stephen K. Bannon had argued in an interview that the U.S. government should be “maniacally focused” on the economic war that he said China is waging on the United States.

But while U.S. business leaders want to avoid a trade war, the idea that the United States should get tougher with China has many supporters.

Indeed U.S. trade groups have become increasingly vociferous in recent years about growing Chinese protectionism and barriers to investment, and they have broadly welcomed Trump’s Aug. 14 order.

More than 20 percent of 100 American companies that responded to a survey by the U.S.-China Business Council said they were asked to transfer technology in the past three years as a condition of market access.

Beijing requires automakers and some other foreign companies in China to work through joint ventures, in which they often are required to give technology to partners that might ultimately become competitors.

Luna Lin contributed to this report.