US stock indices surged at the close of trading on Tuesday, with the Dow Jones Industrial Average and the S&P 500 finishing the session at record highs.

Support came from hopes of easing tensions in the Middle East, as well as strong corporate earnings. Traders enthusiastically welcomed a statement by US Treasury Secretary Scott Bessent that Washington and Tehran could reach an agreement to resume shipping in the Strait of Hormuz as early as Tuesday or Wednesday.

"There is a chance that today or tomorrow we will have an agreement to open the strait," he said in an interview with CNBC.

Oil prices fell sharply on Bessent's statement.

Later, US Secretary of State Marco Rubio said that no final agreements on shipping in the Strait of Hormuz have been reached yet. He expressed hope that an agreement would be reached soon.

Statistics published on Tuesday showed the US trade deficit narrowed by 5.6% in June from the previous month to $73.3 billion from $77.6 billion in May. Analysts on average expected the deficit to decline to $73 billion, according to Trading Economics. US exports fell to a four-month low in June, while imports declined for the first time since January, the Commerce Department reported.

The biggest gainer among Dow components was Caterpillar Inc., whose shares rose 5.6%. The company, which makes equipment for road construction and mining, increased second-quarter net profit by 1.6 times, and its revenue exceeded $20 billion for the first time. Caterpillar raised its annual revenue growth forecast to 15-17% from the previously expected 10-12%.

Cisco Systems Inc. (+5.1%), International Business Machines Corp. (+3.9%), and Amgen Inc. (+2.9%) also rose notably.

Palantir Technologies' market value soared 29.5% by the market close. The provider of big data solutions more than tripled second-quarter net profit and increased revenue 1.9 times, with adjusted profit and revenue beating market expectations.

McDonald's Corp. shares rose 1.2%. The company's adjusted second-quarter profit beat forecasts, while revenue and US comparable sales growth missed them. McDonald's also announced a change in leadership of its US division.

Procter & Gamble Co. (P&G) market capitalization rose 2.1%. CEO Shailesh Jejurikar said in a CNBC interview on Tuesday that P&G is buying US dietary supplement maker Thorne for $3.8 billion. P&G later confirmed this in a filing with the Securities and Exchange Commission (SEC).

The biggest decliner in the Dow was Nike Inc. (-2.6%).

Amazon.com Inc. shares fell 2.3% on news that founder Jeff Bezos sold $4.1 billion worth of company stock.

UnitedHealth Group Inc. (-1.9%) and Chevron Corp. (-1.4%) also declined notably.

The Dow Jones Industrial Average rose 1.71% to 54,085.88 points at Tuesday's close.

The Standard & Poor's 500 increased 1.79% to 7,736.52 points.

The Nasdaq Composite rose 2.59% to 26,584.99 points.