Stocks posted their biggest gains in nearly two months on Tuesday as retail sales figures allayed fears over the economy that had driven a six-week slump in the market.

Many analysts said the rally was likely a one-day wonder. Though still weak, the retail sales data was not as bad as most had expected, which provided an excuse to buy after the market had neared its most oversold conditions in a year.

It's the long-term trend which is still disturbing, said Alan Valdes, director of floor operations at DME Securities in New York. If you look at the S&P 500, they've lost over $1 trillion in value since the beginning of May -- that is telling.

We were so oversold you had to see a plus day.

Many headwinds remain, including concerns over debt problems in Europe and the United States, along with the expiration at the end of this month of the U.S. Federal Reserve's bond-buying program, which has been a key source of liquidity for markets.

U.S. retail sales declined for the first time in 11 months in May, but the fall was less than forecast. China data also helped to ease worries about global growth.

Gains were spread across the board, with the Morgan Stanley retail index <.MVR>, up 2.8 percent, among the best performers. Energy also outperformed, with the S&P energy sector <.GSPE> up 2 percent as oil prices rose.

J.C. Penney Co Inc jumped 17.5 percent to $35.37 after the department store chain named Ron Johnson, Apple Inc's senior vice president of retail, as its new chief executive.

The Dow Jones industrial average <.DJI> gained 123.14 points, or 1.03 percent, to 12,076.11. The Standard & Poor's 500 Index <.SPX> rose 16.04 points, or 1.26 percent, to 1,287.87. The Nasdaq Composite Index <.IXIC> advanced 39.03 points, or 1.48 percent, to 2,678.72.

Expectations for further selling this summer hovered in the background even as the market rallied.

Many investors are eyeing a possible retreat in the S&P 500 to its March low near the 1,250 level. The index closed flat on Monday after falling to near a three-month low last Friday.

That level could be seen as a near-term bottom and attract additional buyers, analysts have said.

The S&P 500 is down about 5.4 percent from its high in early May as recent weak data sparked worries about the sustainability of an economic recovery.

In a sign that individual investors may be losing confidence in the stock market, customer trading slowed substantially last month, with more clients' money moving into cash and out of stocks and other areas, according to brokerage Charles Schwab Corp .

In China, inflation was still a concern after consumer prices rose at their fastest pace in almost three years in May, but industrial output grew from a year ago, in line with forecasts. China's central bank increased the reserve requirement ratio for commercial lenders by 50 basis points.

People that were saying 'hard landing for China'-- so far the numbers don't show that, said Jeffrey Saut, chief investment strategist for Raymond James Financial, in St. Petersburg, Florida.

Options expiration this week also could generate more volume and amplify stock moves as traders adjust their hedges. Such dynamics can lead to pinning where a stock or index closes at or around its corresponding at-the-money option strike.

Volume was light with about 6.45 billion shares traded on the New York Stock Exchange, NYSE Amex and Nasdaq, below the daily average of 7.58 billion.

Advancing stocks outnumbered declining ones on the NYSE by 2,511 to 503, while on the Nasdaq advancers beat decliners 2,034 to 592.

(Reporting by Chuck Mikolajczak; Editing by Leslie Adler)