A volatile day on Wall Street ended in upbeat fashion Tuesday as a late-afternoon rally led by technology stocks pushed the market to a modest gain.
The turnaround helped snap an eight-day trading slump for the Nasdaq composite, which is heavily weighted with technology stocks.
Energy stocks were down as much as 2% during the day, then recovered in late trading to eke out a slight gain.
Crude oil prices declined for the seventh day in a row, the longest losing streak since July 2014. Oil has fallen nearly 18% 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 rose 117.65 points, or 0.7%, to 16,516.22. The Standard & Poor's 500 index went up 15.01 points, or 0.8%, to 1,938.68. The Nasdaq composite climbed 47.93 points, or 1%, 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 also kept traders on edge after sharp losses last week.
The steep downturn in crude oil prices has weighed on the market. The three major U.S. stock indexes are all down for the year, with the Dow and S&P 500 off about 5% and the Nasdaq down 6%.
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, though, 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, chief executive of Ladenburg Thalmann Asset Management. "People here are basically buying the dip."
Eight of the 10 sectors in the S&P 500 index rose. Technology companies gained 1.2%. Healthcare and consumer discretionary stocks notched gains of 1%. Utilities and telecommunications services stocks fell.
Chipmaker Intel climbed 62 cents, or 2%, to $32.68, and Apple rose $1.43, or 1.5%, to $99.96. Among healthcare companies, UnitedHealth Group climbed 2.4%, the biggest gainer in the Dow Jones industrial average. It went up $2.68 to $112.26.
Energy stocks rose 0.4%. The sector remains down 8.5% this year.
U.S. crude oil fell 97 cents, or 3.1%, to $30.44 a barrel in New York. Brent crude, a benchmark for international oils, fell 69 cents, or 2.2%, 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 sank 20 cents, or 4.6%, to $4.11. Consol Energy fell 30 cents, or 4.3%, 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 began Monday and runs for the next several weeks.
Alcoa sank 9% after the aluminum manufacturer reported revenue that fell short of Wall Street's expectations. The stock dropped 72 cents to $7.28.
GameStop tumbled 5.1% after investors were disappointed with the video game store operator's holiday season sales. The stock fell $1.50 to $27.88.
Health insurers fared a bit better. Traders bid up shares in Anthem, which rose $7.24, or 5.6%, to $135.60, and Aetna, which went up $4.08, or 3.9%, to $109.15.
European markets moved higher. Germany's DAX rose 1.6%, while the CAC-40 in France rose 1.5%. The FTSE 100 index of leading British shares gained 1%.
In Asia, China's Shanghai composite closed 0.2% higher, recovering some of its losses from the day before. Japan's Nikkei 225 fell 2.7%. Hong Kong's Hang Seng shed 0.9%, and South Korea's Kospi dropped 0.2%.
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% from 2.17% 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 New York, wholesale gasoline fell 2.8 cents to close at $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.
FOR THE RECORD
3:18 p.m.: An earlier version of this story said wholesale gasoline rose 2.8 cents. It fell 2.8 cents.