Stocks edged lower on Monday on stalled Greek debt talks, but an afternoon rally cut losses in a sign of the underlying resilience the market has shown early in the year.

Major indexes had fallen more than 1 percent as negotiations between the Greek government and private bondholders over the restructuring of 200 billion euros of debt failed to reach an agreement before the start of a summit of European leaders.

But by the afternoon the losses were cut sharply. Optimism that the U.S. markets can decouple from Europe's troubles continues to fuel trading in 2012, with the S&P 500 up 4.7 percent this month. Money managers, some of whom missed the upward move, are buying on dips.

If you're a portfolio manager that didn't start the year off with a bullish outlook, you're worried about being 5-6 percent behind already before the end of January, said Michael James, senior trader at regional investment bank Wedbush Morgan in Los Angeles.

EU leaders did reach agreement at the summit on a permanent euro zone bailout mechanism to come into effect in July.

Most affected by developments in Europe was the financial sector <.GSPF>, which was down 0.9 percent and was the biggest drag on the S&P 500. Bank of America fell 2.8 percent to $7.09.

Material, technology and telecoms stocks led the turnaround after the close of European markets. The S&P 500 materials sector <.GSPM>, which is up over 11 percent already this year, edged up 0.1 percent on Monday.

The Dow Jones industrial average <.DJI> slipped 12.03 points, or 0.10 percent, to 12,648.43. The Standard & Poor's 500 Index <.SPX> fell 3.29 points, or 0.25 percent, to 1,313.04. The Nasdaq Composite Index <.IXIC> lost 2.08 points, or 0.07 percent, to 2,814.47.

Even though the euro zone crisis drags on, the S&P 500 was on track for its best month since October, helped by stronger U.S. economic data and a easing of conditions in Europe's financial system following action from the bloc's central bank late last year.

However, Peter Lee, chief technical strategist at UBS Wealth Management, said many of his clients, who include some big institutional investors, are still cautious after the S&P 500 has climbed over 22 percent from lows in October.

Some buyers are supporting this market, and we think it may be short-covering, he said. It gives the market the illusion it is strong.

Germany sought to tone down reports it was pushing for Greece to give up control over its budget policy to European institutions. Greece was unlikely to accept that scenario, presenting yet another obstacle to a second bailout package for Athens.

Apple shares helped cap losses on the Nasdaq after Morgan Stanley said the iPhone maker could add China Telecom <0728.HK> and China Mobile <0941.HK> as distributors over the next year. Apple rose 1.3 percent to $453.28.

Swiss engineering group ABB agreed to buy U.S. electrical components maker Thomas & Betts Corp for $3.9 billion in cash, sending shares of the company up 22.9 percent to $71.20.

Consumer spending, the main pillar of the U.S. economy, was flat in December as households added to savings after the largest rise in income in nine months. Although the data pointed to a slow start for spending in 2012, economists were cautiously optimistic that an improving labor market will support demand.

(Editing by Kenneth Barry)