NEW YORK (Reuters) - Major U.S. stock indexes ended higher on Tuesday after recovering from steep early losses triggered by fears that hostilities in the Korean Peninsula could escalate.

The S&P 500 fell as much as 0.66 percent after U.S. President Donald Trump warned that all options are on the table for the United States to respond after North Korea fired a ballistic missile over a Japanese island in a new show of force.

“When the president says ‘all options are on the table,’ the best strategy for investors is sometimes to do nothing,” said Brian Jacobsen, senior investment strategist at Wells Fargo Funds Management in Menomonee Falls, Wisconsin.

Market analysts were relieved that the rift did not escalate further, with Trump’s focus on the devastation caused by Tropical Storm Harvey, which was the most powerful hurricane to strike Texas in 50 years when it made landfall last week.

“While it’s possible all these unfortunate events can add up to something more consequential, the (U.S.) economy is pretty darn big and resilient,” Jacobsen said.

The storm shuttered refineries across the U.S. energy hub in Texas but energy shares were little changed, with declines in oil services companies mostly offset by gains in refiners and some producers.

Ernesto Ramos, head of equities at BMO Global Asset Management in Chicago, described the market reaction to the flooding in Houston and surrounding areas as a “very stock-specific situation.”

Shares of insurers fell on uncertainty over their storm-related liabilities. An index of industry stocks .KIX dropped 0.5 percent to end at its lowest in two months.

The Dow Jones Industrial Average .DJI rose 56.97 points, or 0.26 percent, to 21,865.37, the S&P 500 .SPX gained 2.06 points, or 0.08 percent, to 2,446.3 and the Nasdaq Composite .IXIC added 18.87 points, or 0.3 percent, to 6,301.89.

Gains in the Nasdaq were led by the largest names, with Apple, Alphabet, Microsoft, Facebook and Amazon, the biggest U.S. companies by market value, all higher.

Best Buy Co Inc BBY.N tumbled 11.9 percent to $55.02 after the No.1 U.S. consumer electronics retailer warned its strong quarterly sales performance should not be seen as a new normal.

United Technologies Corp UTX.N rose 2.9 percent to $118.70 as it made progress in talks to acquire aircraft component manufacturer Rockwell Collins Inc COL.N in order to bulk up its aerospace business. Rockwell's shares rose 2.1 percent to $130.74.

Nike NKE.N fell 1.9 percent to $52.73 after Morgan Stanley cut its price target by $4, to $64.

Declining issues outnumbered advancing ones on the NYSE by a 1.05-to-1 ratio; on Nasdaq, a 1.08-to-1 ratio favored advancers.

Nearly 285 issues across U.S. exchanges hit their lowest in 52 weeks on Tuesday, more than the average over the last year of close to 230, while 355 hit a 52-week high, far below the average of almost 490 for every day over the last year.

About 5.3 billion shares changed hands in U.S. exchanges, compared with the 5.9 billion daily average over the last 20 sessions.