The S&P 500 clung to slight gains in the close to end at its highest since Dec. 1. Financials and energy led advancers, while utilities fell 2.4 percent and consumer staples closed nearly 1.4 percent lower to lead decliners.
Treasury yields turned higher in midday trade, with the 2-year yield hitting 0.81 percent and the 10-year yield rising to 1.859 percent, their highest since late March.
"I think it was a combination of stronger equity markets and higher oil prices," said Sharon Stark, fixed income strategist at D.A. Davidson.
WTI pared losses and turned higher as oil prices found support from a late-morning Bloomberg report, citing Iraq, that OPEC and other producers would possibly meet in Russia in May to discuss an output freeze proposal. Bloomberg later reported that Russia said there was no agreement on a meeting.
Traders also attributed oil's gains to the EIA's mid-morning report that raised expectations of curbing oversupply with a decline in U.S. production and a lower-than-forecast crude inventory build of 2.1 million barrels. Volatility around the post-settle contract rollover was also a factor.
Read MoreDow, other key stocks form bullish 'golden cross'
The Dow failed to hold 18,100 in the close, with Boeing, Caterpillar and Procter & Gamble contributing the most to declines. Goldman Sachs and UnitedHealth contributed the most to gains.
"We're digesting first-quarter earnings (mostly beating) relatively lowered expectations and the market is telling us we're in an environment where there's no panic about the first quarter and beyond," said Tom Wright, director of equities at JMP Securities.
The CBOE Volatility Index (VIX), widely considered the best gauge of fear in the market, held around 13 after earlier falling to 12.5, its lowest since August 10, 2015. (
"We seem to have a fine balance between the tug of war that is crude prices and earnings that are better than worst case scenario," said Art Hogan, chief market strategist at Wunderlich Securities.
"Right now earnings are winning that tug of war," he said. "To me it feels like correlation between oil and the S&P (breaks down) above $40."
Earlier, oil traded lower but held mostly above $40 a barrel. WTI turned lower in late trade Tuesday after the American Petroleum Institute reported a surprise build and news of settlement in Kuwait's oil worker strike.
Coca-Cola reported earnings that beat slightly on both the top and bottom line. Worldwide case volume was up two percent, slightly below analysts' forecasts. The stock closed about 4.8 percent lower, off lows.
Intel posted earnings that topped expectations, with revenue essentially in line. However, revenue guidance missed expectations and the firm cut its full-year profit margin outlook. Intel also announced it would cut up to 12,000 jobs and that Chief Financial Officer Stacy Smith would leave that post to lead the company's sales efforts. The stock closed nearly 1.3 percent higher.
Read MoreAnalysts raise concern on Boeing aircraft profitability
The major averages struggled for gains in morning trade Wednesday before turning higher, with the S&P 500 and Dow trading closing about 1.5 percent or less below their 52-week intraday highs touched last May.
The "market looks a little exhausted right now. We've encountered some key resistance areas," said John Caruso, senior market strategist at RJO Futures.
"I do think volatility is due to increase here relatively soon. I think there's a lot of question marks hanging into the balance," he said.
On Tuesday, the S&P 500 topped the psychologically key 2,100 level for the first time since early December, while the Dow held above the 18,000 level.
"As the market continues to grind higher and it refuses to sell off, that means the underlying bid is alive and well," said Adam Sarhan, CEO of Sarhan Capital.
Read MoreWhat a Brexit could mean for US banks
In economic news, existing home sales surged 5.1 percent to a seasonally adjusted annual rate of 5.33 million units in March. February's sales pace was revised slightly down to 5.07 million units from the previously reported 5.08 million units.
Overseas, European stocks closed about half a percent higher or more, with the STOXX Europe 600 Banks index outperforming with gains of 2.2 percent. The index is still more than 15 percent lower year-to-date but up 6.45 percent for the month so far.
The Nikkei 225 closed almost 0.2 percent higher while most Asian stocks ended lower. The Shanghai composite fell 2.3 percent, amid reports that China's central bank may not ease as aggressively this year.
Read MoreEarly movers: KO, DISH, TUP, NLSN, GOOGL, INTC, GPN, VMW, YUM & more
The Dow Jones industrial average closed up 42.67 points, or 0.24 percent, at 18,096.27, with Goldman Sachs leading advancers and Coca-Cola the greatest decliner.
The S&P 500 closed up 1.60 points, or 0.08 percent, at 2,102.40, with financials leading five sectors higher and utilities the greatest laggard.
The Nasdaq composite closed up 7.80 points, or 0.16 percent, at 4,948.13.
The Russell 2000 closed up 0.18 percent at its highest level of the year so far but is the only major U.S. index still in correction territory, or more than 10 percent below its 52-week intraday high.
Advancers were a step ahead of decliners on the New York Stock Exchange, with an exchange volume of 966 million and a composite volume of 4.1 billion in the close.
Gold futures for June delivery settled up 10 cents at $1,254.40 an ounce.
—CNBC's Peter Schacknow contributed to this report.
On tap this week:
Earnings: Alphabet, Microsoft, General Motors, Visa, Starbucks, Bank of NY Mellon, Biogen, Under Armour, Southwest Air, Stanley Black and Decker, Imax, Novartis, Union Paicific, DR Horton, Fifth Third, Johnson Controls, Pulte Group, Polaris, Alaska Air, Verizon, Travelers, E*Trade, Norfolk Southern, Boston Beer
8:30 a.m. Initial claims
8:30 a.m. Philadelphia Fed survey
9 a.m. FHFA home prices
Earnings: General Electric, Caterpillar, McDonald's, Honeywell, AutoNation, American Airlines, Synchrony Financial, Kimberly-Clark, SunTrust, LyondellBasell, Steve Madden, Daimler
9:45 a.m. Manufacturing PMI
*Planner subject to change.
More from CNBC.com: