The three major U.S. stock indexes rallied Tuesday afternoon, recouping most of their losses in an earlier rout sparked by warnings from Caterpillar and 3M, two of the largest American manufacturers, that President Trump's trade war is driving up supply costs.

Caterpillar, which makes heavy equipment used in farming and road work, said tariffs on steel, aluminum, and $250 billion of Chinese imports cost the company an extra $40 million in the three months through September. The charges may cut profit by $100 million or more for all of 2018, executives warned.

The Deerfield, Ill.-based firm's stock slid as much as 10 percent to $115.84 in New York trading afterward, helping drag the blue-chip Dow Jones industrial average down more than 500 points before paring losses.

The broader S&P 500, meanwhile, slipped as much as 1.9 percent, and the tech-heavy Nasdaq tumbled as much as 2.3 percent, reflecting longstanding concerns that Trump's tariffs would gradually undermine the benefits of last year's tax cuts. The president maintains the tariffs are necessary to eliminate trade imbalances and bring manufacturing jobs back to America.

By early afternoon, the Dow's daily drop had shrunk to 0.5 percent and those of the S&P 500 and Nasdaq had narrowed to 0.6 percent and 0.4 percent, respectively.

"While our U.S. outlook is positive, recent performance has shown it's not immune to sell-offs," said Mark Haefele, chief investment officer at UBS Global Wealth Management. "Money managers are monitoring the risk that an overheating economy and rising interest rates will spell the end of a long-running bull market," he added, but "we think it's still too early to call time."

[Also read: Harley-Davidson's US sales dip as growth shifts to Europe]

Although many companies shrugged off the impact of the tariffs in the spring quarter, compensating with price increases, economists have said that tactic would grow increasingly painful as more of the duties take effect.

Minneapolis-based 3M, viewed by economists as a bellwether because of the breadth of its products, said tariff-related expenses would shave 15 cents a share from this year's profit and perhaps more in 2019.

"We are anticipating continued increases in raw-material prices," 3M Chief Financial Officer Nick Gangestad told investors on an earnings call. "If I fast-forward a little into 2019, we think tariffs will be having a negative impact on our total sourcing cost. Our view is we have an approximately $100 million headwind from tariffs and that our pricing will more than offset that and raw-material price increases into 2019."

3M's stock-market decline narrowed to 3.9 percent by the close of trading Tuesday, with its shares at $193.50, but not before Trump took to Twitter to reassure voters that his trade strategy will pay off in the long run.

"If a country won’t give us a fair trade deal, we will institute tariffs on them," he declared. "Used or not, jobs and businesses will be created."

While corporate leaders have opposed Trump's trade strategy, with the U.S. Chamber of Commerce undertaking a vigorous marketing campaign against the tariffs, JPMorgan Chase CEO Jamie Dimon conceded earlier this month that they seem to be proving an effective negotiation tool.

The president himself said the same in an early October press conference called to promote revisions to the North American Free Trade Agreement that will increase U.S. access to Canadian markets and ensure greater concentration of car-manufacturing in the region.

"Without tariffs, we wouldn’t be talking about a deal, just for those babies out there that keep talking about tariffs," Trump said. "That includes Congress — 'Oh, please don’t charge tariffs.' Without tariffs, you wouldn’t be — we wouldn’t be standing here."

Trump is unlikely to change his attitude regardless of the outcome of the midterm elections, said Chris Krueger, an analyst with Cowen Washington Research Group, which has tracked federal policy for the past four decades.

If the Republicans keep control of both houses of Congress, the president will consider himself validated and lean in, Krueger said. If the Democrats gain power, the president may blame Republicans who opposed him.

The White House's overarching goal "is to break global supply chains and bring manufacturing and production home," he added. "This is centered around the wistful Trumpian view of a 1950s America."