© Brendan Mcdermid/Reuters
Traders on the floor of the New York Stock Exchange.
Stocks surged Friday as investors cheered an agreement by European leaders to stabilize the region's banks, a pact that helped remove some of the uncertainty that has been plaguing markets.

The broad rally saw the Dow Jones industrial average tack on 278 points and chalk up its best day since June 6.

Still, for the quarter the broader stock market ended lower, down 3.3 percent, marking the first down quarter for the benchmark S&P 500-stock index in the last three after inconclusive Greek elections and concerns about the solvency of Spanish banks roiled financial markets around the world.

The S&P 500 is up 8.3 percent since the start of 2012.

Crucially, euro-zone leaders agreed that countries would be able to recapitalize banks directly without increasing a country's budget deficit.

Such a move serves to end the cycle markets fell into when policymakers bailed out Spanish banks to the tune of $125 billion, but ended up further extending the indebtedness of the Spanish state and shunting existing bondholders down the food chain.

"The key is in separating the banking system from the sovereign system and they had to have seen that," said Paul Mendelsohn, chief investment strategist at Windham Financial Services in Charlotte, Vermont.

"The answer was obvious and (German Chancellor Angela) Merkel made a lot of noise before the meeting and I guess she saw the handwriting on the wall."

Policymakers also agreed to discuss a proposal for a pan-bloc banking union and said they wouldn't force countries that comply with EU budget rules to adopt extra austerity measures or economic reforms.

In addition to the boost the EU agreement gave to the Wall Street rally, investors cited end-of-quarter portfolio adjustments, including reallocation to bonds from stocks after bonds outperformed stocks by a wide margin this month.

Sectors that have been among the most sensitive to developments in the euro zone led gains. U.S. bank stocks were among the market leaders.

Italian and Spanish borrowing costs fell, though they remained not far from recent highs. Market expectations for any action during a two-day European Union summit had all but vanished, giving markets room to bounce on good news.

Brent and U.S. crude oil prices soared on the back of the EU agreement.

The EU summit news overshadowed a batch of mixed U.S. data. U.S. consumer spending stalled in May as auto purchases flagged while consumer sentiment hit a six-month low in June in the latest signs of trouble for the economy.

Although another report on Friday showed manufacturing activity in the Midwest picked up this month, factories saw a modest decline in new orders.

Attention in Europe now turns to next week's European Central Bank meeting. The consensus is that the bank will cut its main refinancing rate by 25 basis points to 0.75 percent and may trim the deposit rate - the rate it pays banks for parking money with it - by 25 basis points to 0 percent.

"You have more fireworks coming next week when the ECB meets on the fifth because I have to believe they are going to cut their interest rates by at least a half to stimulate growth," said Mendelsohn.

Among the few Wall Street decliners, U.S.-traded shares of Research in Motion tumbled in the wake of the company's decision on Thursday to delay the make-or-break launch of its next-generation BlackBerry phones until next year.

Nike shares dropped a day after the world's largest sportswear maker missed quarterly profit estimates for the first time in at least two years.

Ford Motor Co fell after the automaker became the latest large multinational to warn on weakness stemming from Europe, joining the likes of Procter & Gamble Co.

But shares of KB Homes jumped after the fifth-largest U.S. homebuilder reported a narrower second-quarter loss, helped by higher sale prices and net orders.

Reuters contributed to this report.