Stocks finished the final trading day of a weak second quarter with a huge bang as Wall Street cheered a surprise agreement by EU leaders to help the region's struggling banks.
Defying expectations for a "June swoon," the Dow logged its best June gain since 1997, while the S&P 500 and Nasdaq posted their strongest since 1999 and 2000, respectively.
“June is usually the second worst month for the market next to September, but this time was a bit of a fluke," said Art Cashin, director of floor operations at UBS Financial Services. (Read More: Four Good Reasons Not to Trust Today's Rally)
Still, all three major indexes posted significant losses for the quarter.
The Dow Jones Industrial Average surged more than 2 percent for the session, led by BofA and Cisco . The S&P 500 and the Nasdaq also soared to post their best trading day in 2012.
The CBOE Volatility Index, widely considered the best gauge of fear in the market, plunged more than 10 percent to close near 17, hitting a two-month low.
For the month, the Dow rallied 3.93 percent, the S&P jumped 3.96 percent, and the Nasdaq advanced 5.06 percent. BofA was the best performer on the Dow in June, while H-P lagged.
Four S&P sectors are up more than 12 percent this year: Telecom, tech, consumerdiscretionary and health care.
EU leaders at a summit in Brussels agreed that euro area rescue funds could be used to stabilize bond markets without forcing countries that comply with EU budget rules to adopt extra austerity measures or economic reforms.
The deal had followed Spain and Italy's earlier withholding of support for a growth package. European shares jumped to finish at a seven-week highfollowing the deal announcement, but exact details of the agreement have yet to be worked out.
“It’s going to be very interesting when [Merkel] tries to sell this to the German people because this is a very unpopular decision on her part to compromise, but this is a breakthrough that we’ve been waiting for and it bodes very well for the markets,” said Michael Yoshikami, CEO and founder of Destination Wealth Management on CNBC's "Fast Money Halftime Report."
Apple climbed after Pacific Crest raised its price target on the iPad maker to $690 from $630.
Among the few stocks in negative territory, Research In Motion tanked almost 20 percent after the embattled BlackBerry maker posted a wider-than-expected quarterly lossand added it would cut 5,000 jobs. Analysts were clearly disappointed—at least 18 brokerages lowered their price target on the Canadian company.