Stocks surged 2 percent on Thursday after European leaders reached a long-awaited agreement to boost the region's bailout fund and struck a deal with banks and insurers to accept 50 percent losses on Greek bonds.

The S&P 500 was on pace for its best monthly percentage gain since January 1987 on optimism that European leaders were nearing a resolution to the sovereign debt crisis that could remove market uncertainty and drive stocks for the near term.

We are rallying today because the active players, mostly hedge fund managers and tactical investors, have been very neutral to even short until now. The market is up a lot, but they are rushing into getting long because they are capitulating, said James Dailey, portfolio manager of TEAM Asset Strategy Fund in Harrisburg, Pennsylvania.

The Dow Jones industrial average gained 249.60 points, or 2.10 percent, to 12,118.64. The Standard & Poor's 500 Index climbed 27.78 points, or 2.24 percent, to 1,269.78. The Nasdaq Composite Index advanced 50.95 points, or 1.92 percent, to 2,701.62.

The gains on the S&P 500 broke the benchmark index out of a trading range between 1,230-1,250, with the 200-day moving average of 1,274 viewed as the next significant technical resistance level.

Financials were the best performers, with JPMorgan Chase & Co up 6 percent to $36.24 and Citigroup Inc jumping nearly 7 percent to $33.32. The KBW Bank index climbed 4 percent.

After more than eight hours of hard-nosed talks, European heads of state, the International Monetary Fund and bankers sealed a deal that also foresees a recapitalization of hard-hit European lenders and a leveraging of the bloc's rescue fund to give it firepower of 1.0 trillion euros ($1.4 trillion).

Analysts see the European developments removing risk to the U.S. economy and tamping down fears of it spilling over into the global financial system.

We advocate re-risking and do take comfort in the belief that there should be no recession on the horizon, said Keith Wirtz, chief investment officer at Fifth Third Asset Management in Cincinnati, with $18 billion in assets.

The latest economic data showed U.S. growth increased at its fastest in a year in the third quarter, while new U.S. claims for unemployment benefits fell modestly last week.

Exxon Mobil Corp edged up 0.2 percent to $81.25 after the U.S. oil and gas major said profit rose 41 percent in the third quarter, helped by higher crude oil prices and refining margins.

Dow Chemical Co's quarterly profit narrowly missed expectations. Still, the stock rose 8.2 percent to $29.10, along with the broader market.

Of 262 companies in the S&P 500 that have reported quarterly earnings, 72 percent topped Wall Street expectations, according to Thomson Reuters data.

In another piece of economic data, pending sales of existing U.S. homes dropped for a third successive month during September, a real estate industry group reported.

(Additional reporting by Angela Moon and Jennifer Ablan; editing by Jeffrey Benkoe)