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.
Nike also tumbled after the sports-apparel retailer missed earnings expectations and as margins took a hit from costs and a restructuring charge. At least eight brokerages slashed their price target on the company.
And Ford Motors dropped after the automaker said its international losses will likely triple in the second quarter, citing weakness in European sales. At least three brokerages cut their price target on the firm.
JPMorgan ended slightly lower amid reports that regulators have stepped up scrutiny of the financial giant's internal controls, according to the Wall Street Journal.
Facebook slipped following a report that Twitter is seeing more success on its mobile advertising, according to the Wall Street Journal, and after Macquarie initiated coverage of the social-media giant with a "neutral" rating and a $35 price target.
IT management cloud service provider ServiceNow skyrocketed more than 30 percent in its market debut.
Alson on the M&A front, Constellation Brands surged to lead the S&P 500 gainers after the company bought the remaining 50 percent of Crown Imports.
Results of the EU summit trumped a batch of tepid economic news. Consumer sentiment dipped to its lowest level this year, while consumer spending was flat in May for the first time in five months.
The pace of business activity in the Midwest edged upin June, according to the Institute for Supply Management-Chicago's business barometer.
“These reports are more of a psychological indicator that reflects the mood during the survey and doesn’t reflect the future,” said Dwight Johnston, chief economist at California Credit Union League.
Johnston says the economy may be “close to a bottom” and expects consumers to be more active, business spending to grow and hiring to ramp up going forward. He predicts growth of between 2.5 and 3 percent in the second half of the year, barring any overly negative news from the euro zone.
—By CNBC’s JeeYeon Park (Follow JeeYeon on Twitter: @JeeYeonParkCNBC)
On Tap Next Week:
MONDAY: ISM mfg index, construction spending, Wal-Mart 50th anniversary
TUESDAY: Factory orders, auto sales; NYSE early close
WEDNESDAY: INDEPENDENCE DAY - Bond, equity markets closed
THURSDAY: Weekly mortgage apps, Challenger job-cut report, ADP employment report, ISM non-mfg index, oil inventories, chain-store sales
FRIDAY: Non-farm payrolls
More From CNBC.com: