(Reuters) - U.S. stocks roared back to end in positive territory on Thursday following steep losses for much of the session, as equities rebounded for a second day.

The failure of an initial selloff to gain more momentum lent credence to the idea that the extended bout of selling pressure may be coming to an end for now, investors said.

The gains come a day after the major indexes posted their biggest daily percentage increases in nearly a decade. The S&P 500’s two-day percentage gain of 5.9 percent is the best performance for the benchmark index since late August 2015 when the market was in the midst of a downturn over a slowing China.

Even so, all three major indexes remain down more than 9 percent for December. The S&P 500 is on track for its biggest annual percentage drop since 2008.

“The market is right now in a psychological frenzy, both good and bad,” said David Katz, chief investment officer at Matrix Asset Advisors in New York. “There’s fear of the market going down; there’s fear of missing the rebound.”

Stocks were lower for most of Thursday’s session, and strategists said such a pullback was to be expected following the huge jump on Wednesday, when the Dow Jones Industrial Average rose 1,000 points for the first time.

Almost in unison, stocks across market sectors began rising around 2:30 p.m. ET, shortly after the S&P 500 briefly broke below 2,400, a level that has been repeatedly tested during the last several days of choppy trading.

Slideshow ( 4 images )

From there the index surged 3.8 percent to close at its highest point in a week.

Even the clutch of technology and internet stocks that were the biggest drags through the first several hours of trading recovered most or all of their losses. Apple Inc AAPL.O gained 4 percent from its low and Amazon Inc AMZN.O shot up 5 percent; both finished the day about 0.6 percent lower.

Microsoft Corp MSFT.O, which had been among the biggest drags on the S&P 500, surged 4.8 percent to finish 0.6 percent higher on the session, ending up as the third-biggest boost to the index.

“I just think that the selling has been exhausted in the near term. When yesterday’s rally only retraced a portion this morning, buyers came back in at the end of the day,” said Rick Meckler, partner at Cherry Lane Investments, in New Vernon, New Jersey. “The general feeling is that a near-term bottom has been put in.”

The Dow Jones Industrial Average .DJI rose 260.37 points, or 1.14 percent, to 23,138.82, the S&P 500 .SPX gained 21.13 points, or 0.86 percent, to 2,488.83 and the Nasdaq Composite .IXIC added 25.14 points, or 0.38 percent, to 6,579.49.

All 11 major S&P 500 sectors finished in positive territory, with materials .SPLRCM as the biggest percentage gainers.

Slideshow ( 4 images )

Investors also said the steep pullback in recent months, which has seen the Nasdaq confirm a bear market and the S&P 500 come within a whisker of doing so, may have created some bargains that are attracting buyers.

“Certainly there are folks that do recognize an opportunity, they stepped in, but then other people see it as a selling opportunity so that is kind of the back and forth,” said Peter Jankovskis, co-chief investment officer at OakBrook Investments LLC in Lisle, Illinois.

Trade tensions between the United States and China, an expected slowdown in U.S. corporate profit growth and the general health of the economy remain concerns for investors heading into 2019.

A measure of U.S. consumer confidence posted its sharpest decline in more than three years in December, deflating some optimism a day after a report that holiday sales were the strongest in years helped mollify concerns about the health of the economy.

“The consumer has been a big support for this economy and if all of a sudden the consumer starts to get a little bit anxious and spending slows down, that’s going to have an impact,” said David Joy, chief market strategist at Ameriprise Financial in Boston.

About 9 billion shares changed hands in U.S. exchanges, just below the 9.2 billion daily average over the last 20 sessions.

Advancing issues outnumbered declining ones on the NYSE by a 1.20-to-1 ratio; on Nasdaq, a 1.03-to-1 ratio favored advancers.

The S&P 500 posted no new 52-week highs and 4 new lows; the Nasdaq Composite recorded 7 new highs and 270 new lows.