U.S. stocks ended 2009 on Thursday with their best gains since 2003, driven by optimism about the economy's recovery and a brighter outlook for profits.

The benchmark Standard & Poor's 500 index rose 23.5 percent for the year, while the Dow climbed 18.8 percent and the Nasdaq jumped 43.9 percent from its close on December 31, 2008.

It was the market's first annual advance in two years. In 2008, the S&P 500 slid 38.5 percent when the economic crisis led to Wall Street's worst year since the Great Depression.

For Thursday's session alone, though, U.S. stocks declined, with a late-day sell-off pushing all three major indexes down about 1 percent as investors sold some of the year's best-performing stocks to lock in some of 2009's substantial gains.

Most of the year's advance is the result of a nine-month rally, led by gains in technology and materials shares on expectations the economic recovery will spur capital spending and increase demand for energy, metals and other natural resources.

It really was a turnaround year, said Charles Lieberman, chief investment officer of Advisors Capital Management, LLC in Paramus, New Jersey. It shows how much of a recovery there's been.

American Express , Microsoft and IBM were the Dow's top gainers for the year. All three ended Thursday lower, however.

On the other hand, General Electric , long considered a bellwether, finished second to last among the Dow components in terms of 2009 performance, with big oil producer Exxon Mobil Corp in last place.

A LIFT FROM EARNINGS

Signs of an economic rebound, including more than 70 percent of companies beating profit expectations in the second quarter, have driven the S&P 500 up 65 percent since its March 9 closing low. The dollar's weakness throughout much of 2009 also gave the market a strong boost on hopes about exports.

Despite optimism about 2009, Wall Street registered its first-ever negative decade on a total return basis even with dividends reinvested. The S&P 500 is down about 10 percent for the decade, on that basis.

After a fast sell-off late in the session, the Dow Jones industrial average <.DJI> ended down 120.46 points, or 1.14 percent, at 10,428.05. The Standard & Poor's 500 Index <.SPX> slid 11.32 points, or 1.00 percent, at 1,115.10. The Nasdaq Composite Index <.IXIC> lost 22.13 points, or 0.97 percent, to close at 2,269.15.

U.S. financial markets will be closed on Friday for New Year's Day.

WINNING QUARTER, LOSING WEEK

For the fourth quarter, the Dow rose 7.5 percent, the S&P 500 gained 5.5 percent and the Nasdaq jumped 6.9 percent.

But for the week, the Dow was off 0.9 percent, the S&P 500 was down 0.4 percent and the Nasdaq fell 0.7 percent.

The S&P 500's top-performing stock for the year was XL Capital -- up an eye-popping 395.4 percent in 2009. On Thursday, however, XL Capital's stock slipped 0.4 percent to end at $18.33 on the New York Stock Exchange.

Citigroup , down 50.7 percent for the year, was among the worst performers in the S&P 500.

IBM rose 55.5 percent for the year, Microsoft gained 56.8 percent in 2009 and American Express jumped 118.4 percent. For the day, IBM fell 1.3 percent to $130.90, Microsoft dropped 1.6 percent to $30.48 and American Express declined 0.7 percent to $40.52.

S&P OFF 29 PERCENT FROM RECORD CLOSE

Analysts see further upside in stocks in 2010 if the recovery proves sustainable. The U.S. unemployment rate is still at 10 percent -- a 26-year high.

The Dow is down 26 percent from its record closing high on October 9, 2007, while the S&P 500 is down 29 percent from its record close on that same date. The Nasdaq is down 55 percent from its March 10, 2000, closing high. A drop of 20 percent or more technically signifies a bear market.

I don't think we're overbought, Lieberman said.

Emerging markets performed better than the United States and other developed markets, with China's key stock index ending with an 80 percent gain and Brazil's stock market up 83 percent for the year.

The S&P information technology sector <.GSPT> is up 59.9 percent for the year, while the S&P materials sector <.GSPM> is up 45.2 percent.

Telecommunications <.GSPL> was the worst-performing S&P 500 sector, with a gain of just 2.6 percent for the year, followed by utilities <.GSPU>, up 6.8 percent.

Adding to Thursday's bearish tone, the December reading of the Institute for Supply Management-Chicago index, also known as the PMI or purchasing managers' index, was revised downward from the level reported on Wednesday.

Volume was light, with many investors out for the holidays. Just 679.9 million shares traded on the NYSE, well below last year's daily closing average of 1.49 billion.

On Nasdaq, about 1.27 billion shares traded, also sharply below last year's daily average of 2.28 billion.

Declining stocks outnumbered advancing ones on the NYSE by a ratio of 2 to 1, while on the Nasdaq, about 17 stocks fell for every 10 that rose.

(Reporting by Caroline Valetkevitch; Editing by Jan Paschal)