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.

advertisement | advertise on newsday

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.