NEW YORK (Reuters) - The S&P 500 ended higher on Wednesday after a brutal two-day selloff, led by a rebound in energy and technology shares, but the market faltered toward the session’s end as Apple shares surrendered gains ahead of the Thanksgiving holiday.

The Dow also gave up its gains to end flat, while the S&P 500 ended near its session lows, a sign of lingering bearishness.

Worries about slowing global growth and peaking corporate earnings have sapped risk appetite in recent months, throwing into doubt the longevity of the nearly 10-year-old bull market.

Michael Antonelli, managing director of institutional sales trading at Robert W. Baird in Milwaukee, said the late-day weakness, which was likely tied to program selling in thin trading volume, is a disappointment for the bulls.

“It’s ugly end-price action. There’s no way to say it otherwise,” he said. “Everybody’s watching Apple because it’s been one of the drivers of pain. It opened really strong and to give all of that back just means the pain is not over.”

Though the S&P technology index rose 0.6 percent, helped by a 9.7 percent gain in shares of Autodesk Inc, Apple shares ended down 0.1 percent at $176.78 after trading as high as $180.27 during the session.

Software company Autodesk reported third-quarter results above analysts’ estimates and announced an $875 million deal to buy cloud-based software company PlanGrid.

The S&P energy index rose 1.6 percent as oil prices steadied after a 6 percent plunge on Tuesday.

The Dow Jones Industrial Average ended flat at 24,464.69, the S&P 500 gained 8.04 points, or 0.30 percent, to 2,649.93 and the Nasdaq Composite added 63.43 points, or 0.92 percent, to 6,972.25.

Slideshow ( 4 images )

The U.S. stock market will be closed on Thursday for Thanksgiving and will close at 1 p.m. EST (1800 GMT) on Friday.

The Dow and S&P 500 remain in negative territory for the year.

The Cboe Volatility Index, the most widely followed barometer of expected near-term volatility for the S&P 500, was down 1.68 points at 20.8. Traders in the options market expect stocks to remain volatile in the coming weeks.

Volume was light at about 6.5 billion shares. That compares with the 8.5 billion daily average for the past 20 trading days.

“It’s a cautious, measured recovery to recapture some of the lost share price from the past few days,” said John Carey, managing director and portfolio manager at Amundi Pioneer Asset Management in Boston.

“Oil is a big part of it ... It’s brought about an improvement in cyclical stocks,” Carey said, referring to gains in shares of energy and materials companies.

Retailers also recovered, with the S&P retail index ending up 1.1 percent, breaking an eight-session string of losses.

Foot Locker Inc surged 14.9 percent after the footwear retailer’s quarterly same-store sales trumped expectations and boosted other sports retailers.

Slideshow ( 4 images )

Shares of Dick’s Sporting Goods Inc, Hibbett Sports Inc and Nike Inc, a Foot Locker supplier, all gained.

Gap Inc rose 4.7 percent after several Wall Street brokerages took positively to Chief Executive Arthur Peck’s more aggressive plan to close underperforming stores, which is expected to eliminate significant losses.

Gains in Foot Locker and Gap helped push the S&P consumer discretionary index 1 percent higher.

A report by capital markets-focused MNI saying the Federal Reserve may pause its interest rate-hiking cycle as early as spring may have helped to support the market, some strategists said.

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

The S&P 500 posted six new 52-week highs and three new lows; the Nasdaq Composite recorded 14 new highs and 84 new lows.