The Dow Jones Industrial Average snapped its losing streak with its best day since the start of the month.

Major indexes wavered shortly after the opening bell, then climbed in a broad rally following the release of upbeat U.S. economic data. All 11 sectors in the S&P 500 ended higher, with shares of energy and financial companies posting the biggest gains.

The Dow industrials added 150.52 points, or 0.7%, to 20701.50 after eight consecutive sessions of declines. If the blue-chip index had ended lower, it would have notched its longest losing streak since 1978.

Today's Highlights

The S&P 500 rose 16.98 points, or 0.7%, to 2358.57, and the Nasdaq Composite added 34.77 points, or 0.6%, to 5875.14—the biggest one-day jump for both indexes since March 15.

Whether President Donald Trump is able to push his agenda into law or not, “all of the data seems strong, not just in the U.S. but also overseas, and I think that’s a very strong backdrop for corporate profits,” said Dan Miller, director of equities at GW&K Investment Management.

The S&P 500 is up 10% since Election Day despite some recent declines.

The relative resilience of U.S. equities “has to do with the underlying strength of the global economy and the picking-up in [corporate] earnings data,” said Jeroen Blokland, a senior portfolio manager at Dutch asset manager Robeco.

Still, Mr. Blokland is holding back on investing more money in equities because of various uncertainties he thinks could cause markets to wobble. Those include the coming French elections, the ability of the Trump administration to enact its agenda and the path of Federal Reserve policy.

Major indexes got a boost from shares of energy companies Tuesday, which extended gains after Mr. Trump signed an executive order taking steps to unravel his predecessor’s climate-change policies.

Energy and mining shares helped push Australia’s S&P/ASX 200 index up 1.3% to close at its highest level in nearly two years. Japan’s Nikkei Stock Average rose 1.1% on Tuesday after the yen steadied against the U.S. dollar in Asian trading to bring some relief to the country’s exporters.