(AP) -- The U.S. stock market mounted a last-minute comeback to close slightly higher on Monday, snapping a three-day losing streak.
The Standard & Poor's 500 index and the Dow Jones industrial average each eked out a tiny gain, while the Nasdaq composite ended slightly lower.
Consumer staples stocks were among the biggest gainers. Oil and gas companies were hit by another plunge the price of crude oil, which tumbled 5.3 percent to a 12-year low. Chevron lost 1.7 percent and Exxon Mobil fell 1 percent.
The latest downturn in oil comes at a time when investors are increasingly uneasy about the trajectory of China's economy and the possible implications for U.S. company earnings. China's Shanghai composite fell 5.3 percent on Monday.
"Investors have one eye on China, and all that's going on there, and the other eye on oil," said Erik Davidson, chief investment officer at Wells Fargo Private Bank. "Those two things are keeping investors on pins and needles right now."
The Dow added 52.12 points, or 0.3 percent, to 16,398.57. The S&P 500 index rose 1.64 points, or 0.1 percent, to 1,923.67. The Nasdaq fell 5.64 points, or 0.1 percent, to 4,637.99.
All of the major stock indexes are down sharply for the year.
The three indexes hinted at a rebound early Monday, but spent much of the day in the red as investors weighed the implications of another stock market drop in China and the slide in crude. The market appeared headed for a lower close until the final minutes of regular trading, when the Dow and S&P 500 index shifted back into positive territory.
Monday's market action is a slight reprieve from an otherwise rough year so far for investors.
Last week, U.S. stocks posted their worst week in more than four years. It was also the market's worst-ever opening week of a year.
A weakening of China's currency and steep drops in its stock market have stoked worries over the outlook for the world's second-largest economy.
That doesn't bode well for the next round of company earnings, which kicks into gear this week.
Many companies' quarterly results will likely reflect the impact of China's softening economy and lower oil prices, said Jason Pride, director of investment strategy at Glenmede.
"The No. 1 most-mentioned item in third-quarter reports was weakness in China," Pride said. "We'd be surprised if China and oil are not central to the earnings narrative as well."
Alcoa delivered its report card after the close of regular trading on Monday. The earnings were better than analysts had expected. Several banks, including Citigroup, Wells Fargo and J.P. Morgan are scheduled to report results toward the end of the week.
On Monday, Benchmark U.S. crude dropped $1.75, or 5.3 percent, to $31.41 a barrel in New York. The last time it was lower was Dec. 5, 2003, when it closed at $30.73 a barrel. Brent crude, a benchmark for international oils, fell $2, or 6 percent, to $31.55 a barrel in London.
Several energy and mining companies slumped as crude oil and other commodity prices fell.
Freeport-McMoRan sank $1.10, or 20.3 percent, to $4.31, making it the biggest decliner in the S&P 500 index. Consol Energy also slumped, losing 69 cents, or 9 percent, to $7. NRG Energy shed $1.11, or 9.8 percent, to $10.23.
Chevron slid $1.36, or 1.7 percent, to $80.77, while Exxon Mobil lost $1, or 1.3 percent, to $73.69.
All told, energy stocks fell the most among companies in the S&P 500 index, 2.1 percent. The sector is down 8.8 percent this year. That's on top of a loss of 24 percent for 2015.
Consumer staples stocks led the risers pack, adding about 1 percent. Macy's notched the biggest gain in the index, adding $2.93, or 8.2 percent, to $38.82.
HCA Holdings also rose after the hospital operator raised its profit forecast. The stock added $3.56, or 5.5 percent to $67.83.
European markets were down. Germany's DAX slipped 0.2 percent, while the CAC-40 in France lost 0.5 percent. The FTSE 100 index of leading British shares slid 0.7 percent.
In Asia, Chinese stocks sank again after a rebound Friday that analysts suggested was due to buying from a group of state entities dubbed the "National Team." The Shanghai Composite Index fell 5.3 percent and Hong Kong's Hang Seng sank 2.8 percent. Sydney's S&P/ASX 200 lost 1.2 percent, while Seoul's Kospi fell 1.2 percent. Tokyo's markets were closed for a holiday.
Gold fell $1.70 to $1,096.20 an ounce, while silver fell 5 cents to $13.86 an ounce. Copper slipped 5 cents, or 2.4 percent, to $1.97 a pound.
Bond prices fell. The yield on the 10-year Treasury note rose to 2.18 percent from 2.12 percent late Friday.
The euro fell to $1.0856 from $1.0903 and the dollar edged down to 117.74 yen compared with 117.67 yen late Friday.
In other energy trading in New York, wholesale gasoline fell 1.5 cents to $1.113 a gallon, heating oil fell 3.7 cents to $1.015 a gallon and natural gas lost 7.6 cents to $2.396 per 1,000 cubic feet.