The turnaround helped snap an eight-day trading slump for the Nasdaq composite, which is heavily weighted with technology stocks.
Energy stocks slumped as much as 2 percent during the day, then recovered in late trading to see a slight gain.
Crude oil prices declined for the seventh day in a row, the longest losing streak since July 2014. Oil has now fallen nearly 18 percent this year.
“We saw a little bit of weakness in oil and the selling just continued,” said J.J. Kinahan, chief strategist at TD Ameritrade.
All told, the& Dow& Jones industrial average gained 117.65 points, or 0.7 percent, to 16,516.22. The Standard & Poor’s 500 index added 15.01 points, or 0.8 percent, to 1,938.68. The Nasdaq composite climbed 47.93 points, or 1 percent, to 4,685.92.
Investors have been wrestling with fears about a protracted slowdown in China’s economy and the potential fallout for corporate earnings. Uncertainty about Beijing’s ability to manage its financial markets has also kept traders on edge after sharp losses last week. The steep downturn in crude oil prices has also weighed on the market. The three major U.S. stock indexes are all down for the year, with the& Dow& and S&P 500 index off about 5 percent, while the Nasdaq is down 6.4 percent.
Trading looked to take a more positive turn early Tuesday as the major U.S. stock indexes opened higher and oil prices rose. That trend didn’t last, as oil prices turned lower once more, weighing on energy stocks. The market looked like it was headed for a lower close before it reversed course in the final hour of trading.
“You’re seeing very oversold conditions,” said Phil Blancato, CEO of Ladenburg Thalmann Asset Management. “People here are … buying the dip.”
Eight of the 10 sectors in the S&P 500 index rose. Technology companies gained 1.2 percent. Health care and consumer discretionary stocks also notched gains of 1 percent. Utilities and telecommunications services stocks fell.
Chipmaker Intel added 62 cents, or 2 percent, to $32.68, while and Apple gained $1.43, or 1.5 percent, to $99.96. Among health care companies, UnitedHealth Group climbed 2.4 percent, the biggest gainer in the& Dow& Jones industrial average. It added $2.68 to $112.26.
Energy stocks rose 0.4 percent. The sector is down 8.5 percent this year.
U.S. crude oil fell 97 cents, or 3.1 percent, to $30.44 a barrel in New York. Brent crude, a benchmark for international oils, fell 69 cents, or 2.2 percent, to $30.86 a barrel in London.
Traders continued to take their cue from oil prices by parting with stocks in energy and mining companies.
Freeport-McMoRan lost 20 cents, or 4.6 percent, to $4.11. Consol Energy shed 30 cents, or 4.3 percent, to $6.70.
“The trading in oil is particularly precarious, and because of that, everybody is selling energy-related stocks,” Kinahan said. “Nobody wants to be the one holding the bag.”
Investors also had their eye on company earnings season, which runs for the next several weeks.
Alcoa sank 9 percent after the aluminum manufacturer’s earnings included revenue that fell short of Wall Street’s expectations. The stock dropped 72 cents to $7.28.
Health insurers fared a bit better.
Traders bid up shares in Anthem, which rose $7.24, or 5.6 percent, to $135.60, and Aetna, which added $4.08, or 3.9 percent, to $109.15.
European markets moved higher.
Germany’s DAX rose 1.6 percent, while the CAC-40 in France rose 1.5 percent. The FTSE 100 index of leading British shares gained 1 percent.
In Asia, China’s Shanghai composite closed 0.2 percent higher, recovering some of its losses from the day before. Japan’s Nikkei 225 fell 2.7 percent. Hong Kong’s Hang Seng shed 0.9 percent, while South Korea’s Kospi dropped 0.2 percent.
In metals trading, gold fell $11 to $1,085.20 an ounce, while silver fell 12 cents to $13.75 an ounce. Copper slipped 1 cent to $1.96 a pound.
Bond prices rose. The yield on the 10-year Treasury note fell to 2.11 percent from 2.17 percent late Monday. The euro fell to $1.0851 from $1.0871 a day earlier and the dollar rose to 117.69 yen from 117.53 yen.
In other energy trading in N.Y., wholesale gasoline fell 2.8 cents to $1.085 a gallon, heating oil fell 2.5 cents to 99 cents a gallon and natural gas fell 13.9 cents to $2.257 per 1,000 cubic feet.