Whatever deal Washington and Beijing reach over the trade war, President Trump has already scored a big victory: Companies are rethinking their reliance on China.

The two sides are nearing an agreement, with Mr. Trump saying on Thursday that an “epic” trade pact could be weeks away and that he may soon meet with President Xi Jinping, China’s top leader. But already, spurred by tariffs and trade tensions, global companies are beginning to shift their supply chains away from China, just as some Trump administration officials had wanted.

The move, known as decoupling, is a major goal of those who believe the world has grown far too dependent on China as a manufacturing giant. As Beijing builds up its military and extends its geopolitical influence, some officials fear that America’s dependence on Chinese factories makes it strategically vulnerable.

Now companies in a number of industries are reducing their exposure to China. GoPro, the mobile camera maker, and Universal Electronics, which makes sensors and remote controls, are shifting some work to Mexico. Hasbro is moving its toy making to the United States, Mexico, Vietnam and India. Aten International, a Taiwanese computer equipment company, brought work back to Taiwan. Danfoss, a Danish conglomerate, is changing the production of heating and hydraulic equipment to the United States.

Mr. Trump’s victory in this department is not unalloyed. Despite his promises to bring jobs back to the United States, most of the work is shifting to other countries with lower costs. Reshaping global supply chains also takes time, and China will remain a vital manufacturing hub for decades to come.

Still, chief executives say the trade war has prompted a fundamental reassessment of China as the dominant place to make things. Even Chinese companies are expanding overseas, although they still have most of their production in China.

“China was the factory of the world,” said Song Zhiping, the Communist Party chief at the China National Building Materials Group, a state-owned giant. “Things are changing. That’s why Chinese companies are going out of China.”

A spokeswoman for the United States trade representative’s office declined to comment.

While Mr. Trump portrays his trade fight as a clash over jobs, proponents of decoupling within the administration see the effort as a way of contending with a stronger, more aggressive China.

Already, China dominates the market for items like solar panels, and has emerged as the world’s largest producer of cars, car parts and many other sophisticated products. It plans to build jetliners, advanced computer chips, electric cars and other goods of the future.

Any deal is likely to leave in place new American tariffs on cars, aircraft parts, equipment for nuclear power plants and other items that administration officials see as essential for economic and security reasons. But more broadly, the trade hawks hope companies in other industries will also find friendlier countries in which to do business.

China emerged as a manufacturing powerhouse over the past two decades. The work force was low cost and relatively skilled. The Communist Party prevented the emergence of independent labor unions. Subcontractors abounded, meaning companies could strongly negotiate for lower supply costs. China built an extensive network of highways and rail lines. It has a vast and growing local customer base, meaning companies don’t have to go far to sell their products.

Businesses flocked there. China accounted for one-quarter of the world’s manufacturing by value last year, up from 8 percent in 2000, according to the United Nations Industrial Development Organization.

Can China Remain the World’s Factory?

The value created in China by manufacturing last year was bigger than in the United States, Germany and South Korea combined.

But wages and other costs in China have been rising for years. A growing number of businesses complain that Chinese officials too often favor local competitors or don’t do enough to stop intellectual property theft.

The prospect of more trade fights only adds to the reasons to diversify, which also include threats elsewhere like Mr. Trump’s threat to close the border with Mexico and Britain’s troubled exit from the European Union.

“Localization will matter more,” Joe Kaeser, the chief executive of Siemens, one of Germany’s largest conglomerates, said in an interview late last month on the sidelines of the China Development Forum in Beijing. “You’re more resilient to political discussions.”

China may not necessarily oppose some of the efforts to decouple. Beijing has long hoped to shed low-skilled, polluting manufacturing jobs and move higher up the value chain.

“The total size of the work force is falling, the labor cost is rising and we are losing our competitive advantage in low-cost industries,” Miao Wei, China’s minister of industry and information technology, said at the China Development Forum. He added that the country would focus instead on high-tech, innovative industries.

Still, Chinese officials must walk a fine line. As the country’s economy slows, an abrupt shift of work out of China could lead to job losses and instability.

Decoupling efforts appear to be in their early stages. A broad survey by UBS of chief financial officers at export-oriented manufacturers in China late last year found that a third had moved at least some production out of China in 2018. Another third intended to do so this year. The typical company was moving the production for about 30 percent of its exports, UBS found.

Companies now want to depend less on one place, which means looking for an alternative to China, Bill Winters, the chief executive of Standard Chartered Bank, said at the World Economic Forum in Davos, Switzerland, this year.

“People who are concerned at the prospect of greater tariffs on Chinese exports, for example, are looking to move export facilities from China to other countries, including Chinese companies,” Mr. Winters said.

Countries seeking to displace China have begun pointing out that exports from their countries are less likely to face tariffs.

For companies with operations in China, “the trade war between the United States and China creates a new uncertainty,” Airlangga Hartarto, Indonesia’s minister of industry, said in an interview in Davos.

The ability to diversify depends on the industry. Some auto parts companies have run their American factories more hours each day to avoid tariffs on Chinese-made goods, said Razat Gaurav, the chief executive of LLamasoft, a supply chain management company in Ann Arbor, Mich.

By contrast, he said, manufacturers of smartphones and smartphone components — which have generally not been hit by Mr. Trump’s tariffs — have found few places to move work because China dominates that supply chain. Still, some in that industry are shifting too, such as Sony’s closure of a Beijing smartphone factory last month after expanding production in Thailand.

For now, companies are looking for alternatives. Steve Madden, the shoe company, is moving production to Cambodia. Hasbro, the world’s leading toymaker, has a goal for the end of next year “to be 60 percent out of China,” by shifting production to the United States and elsewhere, Brian Goldner, the company’s chairman and chief executive, said in a recent conference call.

Though much of the work leaving China is going to other low-cost countries, some companies are following Mr. Trump’s suggestion that they move production to the United States.

Danfoss, a Danish maker of heating and cooling systems as well as sensors and transmitters, has seen rising costs in China, especially for skilled labor, said Kim Fausing, the company’s chief executive and president. It is also looking for ways to reduce transportation-related emissions of global warming gases.

When Danfoss bought an American heating systems company a year ago and found that the company had recently shifted some work to China, it acted quickly. “The first thing we did after we acquired it was we moved everything back” to the United States, where Danfoss already had a dozen factories, Mr. Fausing said.

The first round of 25 percent tariffs that Mr. Trump put in place last July included hydraulic parts long manufactured by Danfoss in northeastern China. The company transferred production of these parts to the United States as well.

“There is not much of a difference between the costs in China and the United States,” Mr. Fausing said. “You have to have a very good case today to justify producing something in China and shipping it to the U.S.”