Planes filled with iPhones have been leaving the Chennai airport in southern India for months, a last-ditch effort by Apple to delay a tariff calamity.

But time is running out for the world’s largest company. The U.S. and China are feuding and Apple is caught in the middle.

When President Trump last week ignited a trade war, it was clear that Apple could be hit hardest. Trump targeted China, where Apple overwhelmingly makes its devices, slapping the world’s second-largest economy with 54% tariffs that spiraled to 145% amid tit-for-tat retaliation . The lower figure threatened to cut deeply into Apple’s big profit margin from China-made devices sold in the U.S. The higher figure could obliterate it.

Like Nike and other top American brands, Apple became a globalization pioneer working with China. A young executive named Tim Cook recognized the potential of the country’s low-cost, hungry workforce. He built a supply-chain colossus there and became Apple’s chief executive along the way.

More than one million workers churn out cutting-edge devices on a tight schedule. Their work is one of the strongest economic ties between the world’s two superpowers—one in which Apple is essentially one of the largest indirect employers, the other where it delivers the device most essential to daily life.

Cook has deftly played politics in both countries to protect his creation, making strategic investments in China to buy goodwill and working out a tariff exemption during Trump’s first term.

Now Apple is trapped. Its Chinese supply chain is so large and intricate, it can’t be moved easily. The company is studying how it could move some iPhone production to the U.S., according to a person familiar with the matter, but doing so will likely take years.

Diversifying final assembly of its products to other low-cost countries, including India and Vietnam, can help Apple dodge some of the impact of China tariffs, but it can’t offset its dependence on the U.S.’s primary global rival, where many of the key parts inside the device will continue to be made.

Cook has said it would be difficult for Apple to make iPhones in the U.S. There isn’t enough labor , skilled and unskilled. If there was, it would be too expensive. A fully American iPhone could cost $3,500, Wedbush Securities suggested.

“It took China 40 years to build a complex manufacturing supply chain,” said Doug Guthrie , a professor at Arizona State University who previously worked on organizational development for Apple in China. “We used to have that. It’s a disaster that we let it go.”

The company’s last, best hope for avoiding further market turmoil lies with Cook and his ability to secure another tariff exemption, as he did during Trump’s first term . Trump has hinted he would grant exemptions to companies “hit harder” by tariffs. Still, it would seem a temporary solution to what appears to be a more lasting rift between the U.S. and China.

Without an exemption, American consumers are likely to pay more for their iPhones, iPads and Macs, or Apple’s substantial profit margins—and the returns for its widely held stock—will go down. Most likely both.

An Apple spokesman declined to comment.

One reason Apple is so closely tied to China’s electronics supply chain is that the company helped build it. It began working with Chinese suppliers more than two decades ago, and increased production there in 2004 as a new hit product, the iPod, was taking off. It had help from a friendly government, and Apple in turn trained suppliers to meet its exacting standards.

‘iPhone City’

In time Apple helped build an ecosystem of more than 1,000 suppliers in China. The iPhone maker taught them how to operate more efficiently, so they competed with one another, driving down Apple’s costs, said Guthrie. Apple manufacturing partner Foxconn built a compound so large in Zhengzhou that it is known as “iPhone City.”

Combining low costs with premium-price devices means Apple’s share of profits for all smartphone production globally can top 80%, even when its share of device shipments is below 20%, according to Counterpoint Research.

Other countries don’t offer the same promise as a manufacturing hub, Guthrie found when he studied alternatives for Apple. India has lots of workers, but bureaucracy can make it more difficult to move quickly. Apple suppliers in India have focused on two southern Indian states that have more streamlined processes. Apple supplier Foxconn has its main India factories near Chennai . Indian officials are hoping the new tariffs on China will help the country take on more of the Apple supply chain beyond final assembly. But such an effort will take years.

When Stephan Kruger worked in Apple’s supply chain from 2014 to 2018, he saw firsthand the advantages of Chinese production.

At one point he helped suppliers spin up production of the iPhone’s “taptic engine”—the part that simulates clicks, vibrations and other tactile feedback.

In the early part of the year he worked with suppliers to get machines in place, test them and refine the production process so that Apple was ready to boost production later in the summer, ahead of its annual September iPhone event.

No step in the process could be matched in the U.S. It required skilled laborers on the front end who could set up machines to stamp out the metal parts. Those workers also train the low-skilled workers in the production process.

Cook and China

“The U.S., over time, began to stop having as many vocational kind of skills,” Cook told CBS’s “60 Minutes” in 2015. “You can take every tool and die maker in the United States and probably put them in a room that we’re currently sitting in. In China, you would have to have multiple football fields.”

But it is also the low-skilled workers whom Apple needs. In China there isn’t only a massive supply of them available, but under the country’s mobile labor system, they work for only a few months. This army deploys to help Apple increase production volumes ahead of the U.S. holiday season, and then retreats when volumes fall, limiting Apple’s costs.

Not long after Cook succeeded Steve Jobs at Apple’s helm, some criticized the low-key Alabama native for his inability to follow up Jobs’s iPhone with a blockbuster of his own. The assumption was that the iPhone’s growth would slow.

Few appreciated how Cook’s supply-chain genius matched Jobs’s product genius. Cook wrapped the blockbuster with ancillary products and services, and delivered huge revenue growth.

Last year, Apple sold 233 million iPhones, up from 93 million the year Cook became CEO, according to IDC. In December the company’s market capitalization peaked at nearly $4 trillion, and it has been the world’s largest company by that metric for most of the past decade.

Cook has saved his supply chain from political threats before.

In China, Apple has made strategic investments including in research-and-development centers to curry favor with government officials. It was also able to continue production in China despite the country’s strict Covid-era lockdowns.

Write to Rolfe Winkler at Rolfe.Winkler@wsj.com