The year’s most beaten-down stocks are taking a last shot at redemption.

Energy shares, whose 21 percent loss in 2015 is more than twice as big as any other industry, just surged 5.6 percent in three days, posting their strongest rally since November. The advance erased the Standard & Poor’s 500 Index’s annual loss and paced gains that added more than $350 billion to American share prices this week.

How big was the surge? Eight of the 10 biggest gainers in the S&P 500 over the past three days are oil and gas producers, led by Oneok Inc.’s 28 percent increase. The group, which also includes Consol Energy Inc. and Ensco Plc, had an average drop of 61 percent in 2015 through Dec. 18, and an average short interest of 11 percent of shares outstanding. That compares with about 3 percent for all stocks in the S&P 500.

“A lot of people have been short, so if they are squaring up their positions into the year-end and closing up short positions, you’ll see a bid,” said Alan Gayle, senior strategist for Atlanta-based Ridgeworth Investments, which has about $42.5 billion in assets. “The jury is still out on the bull case for energy.”

Oil and gas producers have fallen so far this year that they’ve become the least-loved group in the S&P 500, with an average 6 percent of shares outstanding borrowed and sold in bets the price will fall. The sector’s gains Wednesday were so big that an index of most-shorted equities -- a group of stocks that in 2015 has become virtually synonymous with drillers and miners -- increased 2.6 percent.

It’s another twist in a year that has already featured the highest volatility and smallest gains of any since 2011. Energy shares in the S&P 500 have traded in a 29 percent range since January, almost three times the peak-to-trough swing in the full index, and remain down 38 percent since June of 2014.

“It feels like a squeeze,” in which gains are fueled by bearish traders buying back shorts, Michael Block, chief equity strategist at Rhino Trading Partners LLC in New York, said. “Energy became unloved and you had technical traders looking for a perfect flush. They got too cute about it, we got good data overnight and this morning off we go.”

The S&P 500 added 1.2 percent to 2,064.29 at 4 p.m. in New York, bringing its three-day rally to 2.9 percent and leaving it higher by 0.3 percent in 2015. Energy producers surged 4.2 percent Wednesday, paring a loss this month that reached 12 percent on Dec. 18.

Oil climbed to a two-week high in New York after a report showed U.S. crude inventories declined, easing a supply glut. West Texas Intermediate crude topped $37 a barrel Wednesday, but the gains still left it lower by almost 30 percent in 2015.

That didn’t stop investors from piling into exchange-traded funds (ETFs) that track the oil industry. About $85 million was added to a Vanguard exchange-traded fund composed of energy stocks on Tuesday, the biggest day of inflows since March, according to data compiled by Bloomberg. The ETF has plunged more than 20 percent this year even after adding 5 percent this week.

“There’s a fair amount of money wanting to buy into the energy sector because prices are so beaten up,” Bob Phillips, co-founder and managing principal at Indianapolis-based Spectrum Management Group Inc, said by phone. “Any indication that oil prices are ticking higher gives reason for that speculative money to start taking positions, and that can push the index higher.”