Stocks regained their footing to close higher on Tuesday as investors shook off the tension between the U.S. and North Korea.
The Dow Jones industrial average erased earlier losses to end 56.97 points higher at 21,865.37, with United Technologies and Boeing contributing the most to the gains. The index fell as much as 134.82 points earlier in the session.
"I think the market has now taken a more neutral stance to the situation in North Korea," said Mark Luschini, chief investment strategist at Janney Montgomery Scott. The initially sharp downturn maybe was "a function of traders selling first and asking questions later, and then realizing that the situation had not deteriorated further."
The Nasdaq composite also erased losses to close 0.3 percent higher at 6,301.89 after Apple hit a record high. The turned positive in afternoon trade, ending the session 0.1 percent higher 2,446.30, with industrials leading four sectors higher.
A South Korean military official told NBC News that the missile was fired around 5:57 a.m. local time on Tuesday. The official said that the missile flew for about 2,700 kilometers (1,678 miles), reaching a maximum altitude of 550 kilometers (342 miles).
"Tensions between North Korea and the US have, in our view, reached levels unseen since 1994, when the Clinton administration considered air strikes on North Korea's main nuclear facility at Yongbyon," said Young Sun Kwon, senior economist at Nomura, in a note Tuesday. "We see today's provocation as in line with our base case for the peninsula – that tension will remain elevated for some time, but also remain contained."
U.S. stock futures sold off on the news, while international stock markets pulled back. In Europe, the Stoxx 600 index fell 1.04 percent, while Asian stocks closed broadly lower.
"It seems like the initial anxiety has left the market for the moment," said Daniel Deming, managing director at KKM Financial. "I think the overnight markets were reacting to the unknown factor."
Japanese Prime Minister Shinzo Abe told reporters the missile fired by North Korea was a ballistic missile that flew over Japan.
Investors increased their exposure to traditional safe havens after the news broke, including gold and U.S. Treasurys. Gold futures for December delivery rose 0.27 percent to settle at $1,318.90 per ounce — its highest level since September 2016 — while the 10-year Treasury yield hit its lowest level since November.
The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, briefly rose more than 20 percent before holding about 4 percent higher.
"I think [Steve] Bannon sort of laid out how this thing is going to play out," said Crit Thomas, global market strategist at Touchstone Investments. "There's not much we can do. Our hands are tied."
Bannon, the former chief strategist to Trump, said in an interview with the American Prospect earlier this month that there is "no military solution" to North Korea.
Tensions between the U.S. and North Korea had risen earlier this month after Trump said North Korea would face "fire and fury" if it continues to make threats to the U.S. Equities pulled back before rebounding slightly.
In economic news, the S&P CoreLogic Case-Shiller home price index rose slightly from May to June. Consumer confidence hit 122.9 in August, higher than the expected number of 120.3.
On Monday, stocks closed little changed as investors digested the aftermath of Hurricane Harvey, which crippled Houston and other parts of South Texas. Houston is home to several major U.S. oil refineries.
—CNBC's Christine Wang contributed to this report.