Oil recovered from a sharp overnight decline to settle up 28 cents, or 0.88 percent, at $32.15 a barrel.
The rise in oil prices helped the major U.S. averages come well off session lows in midday trade and turn higher. The U.S. Department of Energy's weekly crude inventory data said U.S. oil barrels rose by 3.5 million, about half what the American Petroleum Institute reported late Tuesday.
"Probably the DOE report is actually helping as support to WTI today. That's why it's not falling as it was in the pre-market," said Luana Siegfried, energy research associate at Raymond James. She noted inventories of crude, gasoline and distillates fell by 0.4 million barrels a day, versus estimates for a build of 1.1 million barrels a day.
Oil production in the lower 48 states fell for a third-straight week to 8.588 million barrels a day. The Association of American Railroads report released Wednesday also showed a drop in carloads transporting oil for the week from the same period last year.
"We are significantly ramping up the pace at which production is coming down. ... (With the drop in rail transports) you're getting a lot closer to getting in balance," said Art Hogan, chief market strategist at Wunderlich Securities.
Financials pared losses to close down 0.2 percent as the only S&P 500 decliner, while energy and materials reversed losses to lead gains. The S&P 500 closed within 10 percent of its 52-week intraday high, out of correction territory.
"It's sort of a reflex bounce (in oil). It's not enough to pull the market into positive territory. It's primarily the financials that are dragging (down) the market," Marc Chaikin, CEO of Chaikin Analytics, said earlier as stocks came off session lows.
"When financial stocks are trading poorly that's an indication there's a lack of confidence in the system and it has negative implications for the market," he said.
Gold futures for April delivery settled up for a second-straight day at $1,239.10 an ounce, up $16.50. Gold futures came off session highs and Treasury yields turned higher as stocks gained in afternoon trade, with the 2-year yield at 0.76 percent and the 10-year yield at 1.75 percent.
"Right now you're seeing the fear trade coming off. ... It looks like investors are coming back in for the time being," said John Caruso, senior market strategist at RJO Futures.
The Russell 2000 led the intraday recovery, reversing a 1.5 percent decline to close about 1 percent higher. In a similarly sharp turnaround, the three major U.S. averages closed higher, with the Nasdaq composite outperforming with gains of almost 0.9 percent.
The Dow transports held about half a percent lower in the close.
"The market got overbought up until yesterday and the weakness in oil, the weakness in the yuan, the weakness in European banks is just a reminder the overarching concerns people have are still there," said Peter Boockvar, chief market analyst at The Lindsey Group.
European stocks closed about 2 percent lower or more. The STOXX Europe 600 fell nearly 3 percent, ending almost 40 percent below its 52-week intraday high.
Overnight, the Chinese yuan midpoint fix was also set slightly weaker against the dollar. However, the Shanghai composite closed about 0.9 percent higher while most Asian equities declined.
The U.S. dollar index traded little changed, with the euro steady at $1.10 and the yen at 112.09 against the greenback. Pound sterling continued to weaken against the dollar amid concerns over the U.K.'s possible departure from the European Union.
"The percentage moves you're seeing in the British pound are disruptive for equity markets. The percentage moves you're seeing in the yen are disruptive," Hogan said.
U.S. stocks extended opening losses after new home sales for January hit 494,000, below the expected 520,000, while the Markit Flash February report on services PMI came in at 49.8, down sharply from 53.2 in January and a touch below the key 50.0 level.
Traders said there was not a fundamental reason for the decline in stocks following the services PMI given the light trade volume and the relative newness of the indicator.
"I don't think the data matters. It's about fear. ... PMI has been weak everywhere. That's not news," said Ilya Feygin, managing director and senior strategist at WallachBeth Capital.
However, the soft economic reports came after Fed policymakers indicated rate hikes remain a possibility.
Read MoreOil, Fed in focus for Street
Richmond Federal Reserve President Jeffrey Lacker said in a Reuters report Wednesday there is still a case for raising interest rates further, a sign the central bank's internal debate over rate hikes remains a live one.
Dallas Federal Reserve President Robert Kaplan said later on Wednesday in a Reuters report that his more downbeat assessment of the U.S. central bank's path of rate hikes will be reflected at the next policy meeting in March.
Late Tuesday, Fed Vice-Chairman Stanley Fischer said that Fed officials "simply do not know" what course of action they would take at their next meeting three weeks from now, adding that it was too early to assess the impact of current market volatility.
St. Louis Fed President James Bullard is due to speak after the closing bell at 7.00 p.m. ET.