Luana Siegfried, energy research associate at Raymond James, was skeptical of the likelihood of a deal. "So far it's more trading on news than any specific fact," she said, also attributing the gains in oil to a rebound from Tuesday's decline.
Iran Oil Minister Bijan Zanganeh said he supports any effort to stabilize the market and prices, according to a Reuters report citing the Iranian oil ministry's official Shana news agency. The Iran oil minister also said in the report the Tehran oil producers meeting was good.
Zanganeh did not explicitly say in his remarks quoted by Shana that Iran would keep its own output at its January level.
Read MoreOil production freeze deal is questionable
"You have the credible possibility for progress that finally makes sense," said Art Hogan, chief market strategist at Wunderlich Securities.
"The narrative continues to get louder and more believers in a commodity complex that was leaning in the wrong direction to begin with," he said.
The major averages closed off session highs. Earlier, stocks extended gains after the afternoon release of the Fed minutes with the Dow briefly adding 289 points to swing into positive territory for February in intraday trade. The index ended the session up about 257 points, or down 0.08 percent for the month so far. Boeing contributed the most to gains in the Dow.
Read MoreRally time? Some think so, but be careful
The S&P 500 topped the psychologically key 1,900 level in the close for the first time since Feb. 4 and ended within 10 percent of its 52-week intraday high, out of correction territory. Energy closed nearly 3 percent higher to lead advancers.
John Caruso, senior market strategist at RJO Futures, attributed most of the rally Wednesday to a short squeeze. "I do believe this rally is going to run out of steam pretty soon. We have got some irrational exuberance going on over here," he said.
The Nasdaq composite outperformed, closing 2.2 percent higher as Priceline surged 11.2 percent. The travel website operator reported a higher-than-expected quarterly profit after hotel and rental car bookings rose, with travel demand suffering only briefly from the Nov. 13 Paris attacks, Reuters said. Apple gained 1.5 percent, while the iShares Nasdaq Biotechnology ETF (IBB) rose 2.9 percent.
Read MoreCashin: I won't believe in the stock rally until...
In economic news, industrial production for January rose 0.9 percent, while capacity utilization was 77.1 percent.
"I think the recent macro indicators we have received have been sufficiently positive to provide a lift to equities for now," John Lonski, chief economist at Moody's, said, noting Friday's better-than-expected retail sales and Wednesday's industrial production report.
"We have indications that U.S. spending will provide sufficient buoyancy to corporate revenues and profitability in 2016," he said. "Nevertheless, the performance by both categories will be below average for an economic recovery."
U.S. producer prices unexpectedly rose last month, rising 0.1 percent after falling 0.2 percent in December. Excluding food and energy, PPI rose 0.4 percent.
Housing starts fell 3.8 percent in January, while building permits fell 0.2 percent.
The minutes from the latest Federal Reserve meeting showed policymakers worried last month that tighter global financial conditions could hit the U.S. economy and considered changing their planned path of interest rate hikes in 2016.
The "market is thinking the Fed is going to be more supportive and cognizant of emerging market slowdown," said Krishna Memani, chief investment officer at Oppenheimer Funds.
"The data flow over the last week or two has actually been OK. What (policymakers are) worried about is more long-term issues that hang over the market," he said, referring to China, financial market volatility and the strong dollar.
Treasury yields held near earlier highs, with the 2-year yield at 0.75 percent and the 10-year yield at 1.81 percent. Both yields hit their highest in more than a week.
The U.S. dollar index traded flat, with the euro near $1.113 and the yen at 113.89 yen against the greenback.
St. Louis Fed President James Bullard is due to speak after the market close.