Investors were relieved after European leaders crafted a deal to slash Greece's debt load and prevent the crisis there from engulfing larger countries like Italy. The package is aimed at preventing another financial disaster like the one that happened in September 2008 after the collapse of Lehman Brothers.
But some analysts cautioned that Europe's problems remained unsolved.
The market keeps on thinking that it's put Europe's problems to bed, but it's like putting a three-year old to bed: You might put it there but it won't stay there,'' said David Kelly, chief market strategist at J.P. Morgan Funds.
Kelly said Europe's debt problems will remain an issue until the economies of struggling nations like Greece and Portugal grow again.
Commodities and Treasury yields soared as investors took on more risk. The euro rose sharply against the dollar.
Stronger U.S. economic growth and corporate earnings also contributed to the surge. The government reported that the American economy grew at a 2.5 percent annual rate from July through September on stronger consumer spending and business investment. That was nearly double the 1.3 percent growth in the previous quarter.
Banks agreed to take 50 percent losses on the Greek bonds they hold. Europe will also strengthen a financial rescue fund to protect the region's banks and other struggling European countries such as Italy and Portugal.
This seems to set aside the worries that there would be a massive contagion over there that would have brought everything down with it,'' said Mark Lamkin, head of Lamkin Wealth Management.
The Dow Jones industrial average soared 339.51 points, or 2.9 percent, to 12,208.55. That was its largest jump since Aug. 11, when it rose 423.
All 30 stocks in the Dow rose, led by Bank of America Corp. with a 9.6 percent gain. It was the first time the Dow closed above 12,000 since Aug. 1.
Even with Thursday's gains, the Dow remains 4.7 percent below the high for the year it reached April 29. The Dow has fallen every month since then due to a combination of a slowdown in the U.S. economy, a worldwide parts shortage after the earthquake and tsunami in Japan, and concerns about the European debt crisis. The Dow is now at approximately the same level it traded at on July 28.
Stocks fell for much of August in the wake of a last-minute deal to prevent the U.S. government from defaulting on its debt.
But anticipations of a solution to Europe's debt problems and signs that the U.S. economy is not in another recession have lifted stocks higher throughout October.
The Dow is up 11.9 percent for the month so far. With only two full days of trading left in the month, the Dow could have its biggest monthly gain since January 1987.
The S&P 500 rose 42.59, or 3.7 percent, to 1,284.59. Those gains turned the S&P positive for the year for the first time since Aug. 3, just before the U.S. government's debt was downgraded. The index is up 13.5 percent for the month, its best performance since a 16.3 percent gain in October 1974.
The Nasdaq composite leaped up 87.96, or 3.3 percent, to 2,738.63.
Small-company stocks rose more than the broader market. That's a sign investors were more comfortable holding assets perceived as being risky but also more likely to appreciate in a strong economy. The Russell 2000 index jumped 5.3 percent.
Raw materials producers, banks and stocks in other industries that depend on a strong economy for profit growth led the way. Copper jumped 5.8 percent to $3.69 a pound and crude oil jumped 4.2 percent to $93.96 a barrel.
The euro rose sharply, to $1.42, as confidence in Europe's financial system grew. The euro was worth $1.39 late Wednesday and had been as low as $1.32 on Oct. 3. European stock indexes also soared. France's CAC-40 rose 6.3 percent and Germany's DAX jumped 6.1 percent.
Investors sold U.S. Treasury notes and bonds, an indication they were moving away from safer investments. The yield on the 10-year Treasury note, which moves in the opposite direction of its price, rose to 2.39 percent from 2.21 percent late Wednesday.
European leaders still have to finalize the details of their latest plan. French President Nicolas Sarkozy spoke with Chinese President Hu Jintao amid hopes that countries with lots of cash like China can contribute to the European rescue.
Past attempts to contain Europe's two-year debt crisis have proved insufficient. Greece has been surviving on rescue loans since May 2010. In July, creditors agreed to take some losses on their Greek bonds, but that wasn't enough to fix the problem.
Worries about Europe's debt crisis and a weak U.S. economy dragged the S&P 500 down 19.4 percent between April 29 and Oct. 3. That put it on the cusp of what's called a bear market, which is a 20 percent decline.
Since then, there have been a number of more encouraging signs on the U.S. economy. Despite the jitters over Europe, many large American companies have been reporting strong profit growth in the third quarter.
Dow Chemical rose 8.2 percent after its profit last quarter rose 59 percent on strong sales growth from Latin America. Occidental Petroleum Corp. jumped 9.7 percent after reporting a 50 percent surge in income.
Citrix Systems Inc. rose 17.3 percent. The technology company's revenue rose 20 percent last quarter, and it forecast growth of up to 13 percent for 2012. Akamai Technologies Inc., whose products help speed the delivery of online content, jumped 15.4 percent after the company reported earnings that beat analysts' expectations.
Avon Products Inc. fell 18 percent, the most in the S&P 500, after the company said the Securities and Exchange Commission is investigating its contacts with financial analysts and Avon's own probe into bribery in China and other countries.
Nine stocks rose for every one that fell on the New York Stock Exchange. Volume was heavy at 6.5 billion shares.