Oil prices and U.S. stock futures whipsawed Tuesday night after Iran fired on Iraqi facilities housing U.S. troops, but markets calmed and eventually rebounded after President Trump eased fears that a skirmish was going to escalate into a full-blown war.

All three major U.S. stock indexes ended in positive territory, with the technology-heavy Nasdaq composite hitting an all-time high of 9,129, a gain of 60 points, or 0.67 percent. The Dow Jones industrial average posted a 161-point gain after having sunk more than 400 points on the overnight scares. The Dow finished at 28,745, a 0.56 percent gain. The Standard & Poor’s 500 index ended the day at 3,253, a 16-point advance, after having struck an all-time high during the day.

In an address to the nation just before noon on Wednesday, Trump said the United States would impose additional economic sanctions on Iran but that “the U.S. is ready to embrace peace with all who seek it.”

The president’s statement calmed investors, and stocks took off.

Iran responded. No lives were lost. America is back to business. Next?” said Michael Farr, president of Farr, Miller & Washington, a D.C. investment firm. Farr said markets had rallied on the new “peace.”

But there was skepticism over whether the peace will hold and for how long.

“The ‘all clear’ has yet to be signaled, as tightened economic sanctions will likely fan the flames of hostility,” said Sam Stovall, chief investment strategist at CFRA.

The analysts saw Iran’s ballistic missile attack on American bases in Iraq as a face-saving move for Tehran, allowing it to say it had followed through on its promised retaliation for the United States killing of a top military commander. “Once the smoke cleared, literally, from the Iranian missile attacks, it was clear that our worst fears were not realized. No U.S. fatalities and no damage to any oil infrastructure,” said John Kilduff, an analyst with Again Capital.

“Investors concluded that neither Iran nor the U.S. want to up the ante,” said Ed Yardeni, president of Yardeni Research.

Investor anxiety also was seen in the surge of gold and bitcoin prices overnight. Both gold and bitcoin are considered to be safe investments during waves of economic volatility or political upheaval. Those markets pared back Wednesday morning from their late-night highs.

“You can put money into what is perceived as a safe haven, such as bitcoin and gold today,” said Ivan Feinseth, chief investment officer of Tigress Financial Partners. “You can risk on, risk off with a mouse click.”

Meanwhile, in the oil market, Brent crude and West Texas Intermediate pulled back after spiking more than 3 percent in the hours after the missile attacks. A barrel of WTI was down more than 4 percent in late afternoon trading on Wednesday. Brent crude, which is seen as more vulnerable to an interruption, was trading down more than 3 percent late in the day.

So long as oil kept flowing out of the region, analysts expected no immediate impact on consumer gas prices. Last week, immediately after Iranian Maj. Gen. Qasem Soleimani was killed in an airstrike ordered by Trump, crude oil prices jumped about 3 percent and investors braced for retaliation.

On Tuesday night, Trump tweeted that “All is well!” Meanwhile, Iran’s Islamic Revolutionary Guard Corps claimed that dozens of U.S. soldiers were killed.

“All is well! Missiles launched from Iran at two military bases located in Iraq. Assessment of casualties & damages taking place now. So far, so good! We have the most powerful and well equipped military anywhere in the world, by far! I will be making a statement tomorrow morning,” Trump wrote.

Aerospace giant Boeing was one of the biggest drags on the Dow. Early Wednesday, a Ukrainian passenger jet carrying more than 170 people crashed in Iran shortly after takeoff. Iranian state media quoted a senior official at Tehran’s main international airport saying that the Boeing 737-800 crashed probably because of technical difficulties.

But Ukraine banned all flights from Iranian airspace, as did several other countries in response to escalating tensions between Iran and the United States.

The crash comes at a time of extreme tumult for Boeing, which last month fired its chief executive, Dennis Muilenburg. The century-old American company has struggled to overcome two deadly airplane crashes blamed on a faulty software program and poor corporate oversight.

“Regardless of what led to the crash, a 737 crash of some sort has been in the news in each of the last three years,” said Jamie Cox of ­Richmond-based Harris Financial Group. “Investors are rightfully nervous of what the future holds for a company whose reliability quotient is being questioned.”

Still, the Dow was buoyed by strong payroll numbers for the end of 2019. A report Wednesday from ADP and Moody’s Analytics said companies added 202,000 positions in December as the solid labor market headed into 2020.