Stocks rose on Wednesday after President Donald Trump's comments on the Iran conflict eased worries of further escalation in U.S.-Iranian tensions.

The Dow Jones Industrial Average gained 161.41 points, or 0.6% to close at 28,745.09. The Nasdaq Composite advanced 0.7% to 9,129.24 and notched intraday and closing records. The S&P 500 climbed 0.5% to 3,253.05and hit an intraday all-time high.

The Dow was up as much as 282 points, or 1%. The S&P 500 and Nasdaq gained as much as 0.9% and 1.1%, respectively. In the final minutes of trading, the major averages came off their highs amid unconfirmed reports of explosions near Baghdad's Green Zone.

Trump said Iran appeared to be "standing down" after that nation attacked the Ain al-Asad airbase overnight. However, he added the U.S. will "immediately impose additional punishing economic sanctions on the Iranian regime." News of the attack sent stock futures tumbling overnight.

"Now, as the president has to some degree defused some of the anxiety, so you're getting … a little bit of a sigh of relief rally here," Art Cashin, director of floor operations at the NYSE for UBS, said on CNBC's "Squawk Alley."

Oil futures fell from their highest levels of overnight trading, lowering concerns of a possible surge in fuel prices. WTI crude futures were up more than 4% at one point, but settled down nearly 5%.

The president's comments pressured safe havens such as gold as investors flocked back into riskier assets. Gold futures for February delivery dropped 0.9% to settle at $1,560.20 per ounce. Overnight, the precious metal jumped to its highest level in about seven years.

Investors around the globe had been bracing themselves for a bigger conflict between Iran and the U.S. after last week's killing of Gen. Qasem Soleimani, a top-ranking Iranian military official. But Trump said there were no American casualties from Tuesday night's airstrikes. The attacks did not target oil infrastructure, boosting investor sentiment as well.