The major averages held most of their gains in the close, after a brief dip into negative territory in morning trade.
"In general, if the price of crude stops going down, that takes away some concern," said Marc Chaikin, CEO of Chaikin Analytics. "When you look at what's leading the charge, it's the three sectors that have been weak."
He expects a year-end rally to bring the S&P 500 to 2,080.
U.S. crude settled up 33 cents, or 0.92 percent, at $36.14 a barrel. Brent settled down 24 cents, or 0.66 percent at $36.11 a barrel. The last time brent settled below WTI was in August 2010, although brent did briefly cross below in January of this year. Both commodities remain near multi-year lows.
Analysts also attributed some of the gains in stocks to year-end seasonal factors. U.S. markets close early Thursday, Christmas Eve, and are shut Friday for Christmas Day.
"I would say it's just people looking beyond. I just think people are bottom-fishing here," said James Meyer, chief investment officer at Tower Bridge Advisors.
The Dow Jones industrial average posted its eighth-straight session with a gain or loss of more than 100 points. The index is on pace to break a three-quarter losing streak but is still nearly 2.3 percent lower for the year so far.
DJIA 8-day performance
The S&P 500 is down about 1 percent year-to-date, on track to snap a three-year win streak.
The Nasdaq composite is up 5.6 percent for the year so far.
In economic news, the National Association of Realtors said existing home sales declined 10.5 percent in November, far greater than expected.
"It could be a timing issue related to this new rule (on paperwork). I'm giving the NAR the benefit of the doubt. … I don't think too many people are putting too much stake in what the NAR is saying," said Peter Boockvar, chief market analyst at The Lindsey Group.
"I don't think there's really much left to look at into year-end," Boockvar said, attributing Tuesday's stock moves mostly to "year-end squaring of positions."
The SPDR S&P Homebuilders ETF (XHB) closed up 0.8 percent.
The final read on third-quarter GDP came in at an annualized rate of 2 percent. Economists polled by Reuters expected annual growth of 1.9 percent, down slightly from the second estimate of 2.1 percent but above the advance estimate of 1.5 percent.
"I think the GDP is being well-received and it just suggests we're going to see solid but modest growth and of course inflation is well-contained and of course the Fed is not likely to be overly aggressive," said Peter Cardillo, chief market economist at First Standard Financial.
The Richmond Fed manufacturing index for December was 6, up from a minus 3 read last month and minus 1 in October.
The U.S. dollar index held mildly lower, with the euro near $1.095 after earlier hitting $1.0984, its highest level against the dollar in nearly a week. The yen was relatively steady near 121 yen against the greenback in the close.
Treasury yields held mildly higher, with the 2-year yield at 0.97 percent and the 10-year yield near 2.23 percent in afternoon trade.
European and Asian stocks ended mostly flat to higher. The Nikkei 225 closed mildly lower.
In corporate news, Nike is scheduled to report earnings after the closing bell. The stock closed up 1.58 percent and is the top performer in the Dow year-to-date with gains of more than 35 percent.
Chipotle shares continued to fall, hitting a fresh 52-week low and closing down 5.25 percent. JPMorgan downgraded the stock to "neutral" from "overweight" citing the new food safety issues. News broke Monday that the CDC is investigating a different E. coli strain at Chipotle. The stock is down more than 25 percent for the year so far.
Read More Early movers: CAG, CMG, ESRX, SCS, F, BHP, GE, VRX, CS, LUV & more
The Dow Jones industrial average closed up 165.65 points, or 0.96 percent, at 17,417.27 with Caterpillar leading advancers and Apple the only decliner.
The S&P 500 closed up 17.82 points, or 0.88 percent, at 2,038.97, with consumer staples leading all 10 sectors higher.
The Nasdaq composite closed up 32.19 points, or 0.65 percent, at 5,001.11.
About three stocks advanced for every decliner on the New York Stock Exchange, with an exchange volume of 849 million and a composite volume of 3.5 billion in the close.
The CBOE Volatility index (VIX), widely considered the best fear gauge for the market, held near 16.5.
Gold futures settled $6.50 lower, at $1,074.10 per ounce.
—CNBC's Patti Domm contributed to this report.
On tap this week:
7 a.m.: Mortgage applications
8:30 a.m.: Durable goods
8:30 a.m.: Personal income
10 a.m.: New home sales
10 a.m.: Consumer sentiment
11 a.m.: Oil inventories
Stock market closes at 1 p.m.
8:30 a.m.: Initial claims
10:30 a.m.: Natural gas inventories
Christmas Day holiday
*Planner subject to change.
More From CNBC.com: