Global stocks and the euro soared on Friday after European leaders surprised markets with an agreement that included using their bailout funds to recapitalize struggling banks directly.


The breakthrough came at a period of uncertainty in financial markets tied to the debt crisis in euro zone countries and concerns about global economic growth. Analysts said that after multiple previous summits by euro zone leaders to address the problems, market expectations had been low for an aggressive outcome.


While details of the plan still needed to be worked out, the euro zone leaders said that the use of bailout funds to recapitalize Spain’s struggling banks directly would take place once they have created a structure for joint bank supervision under the European Central Bank.


They also agreed to ease the conditions under which the bailout funds could buy government bonds, a move that could benefit Italy if its government financing costs remain under pressure.


The news set off a broad European rally with gains of more than 4 percent that reverberated in the United States markets. At the close, the Dow Jones industrial average gained 2.2 percent, or about 277 points, to 12,880.09. The Standard & Poor’s 500-stock index rose 2.5 percent to 1,362.16 and the Nasdaq composite index jumped 3 percent to 2,935.05.


The rally came on the last day of trading for the first half of the year, which the three main Wall Street indexes closed out higher. The Dow rose 5.4 percent for the year to date, while the S.&P. was up 8.3 percent and the Nasdaq gained 12.66 percent.


But analysts noted that rallies after numerous other high-level European meetings — at least 19 in more than two years — aimed at tackling some of the Continent’s thorniest issues were short-lived.


While none were anticipating that Friday’s pact would end the euro zone problems, some analysts said that if the European Central Bank follows through with some support, the gains might have some staying power.


“The sense that these officials have a tin ear to the markets is receding as they directly address the big concerns,” said Alec Young, global equity strategist with S.&P. Capital IQ. “There’s a sense that ‘hey, these guys are listening.’ It’s a real sign of compromise. We hadn’t seen that in the past.”


Rick Bensignor, the chief market strategist for Merlin Securities, said, “Clearly, the market is taking this as the most significant of potential outcomes that we have seen for meetings like this, and it may have more significance than just short-term implications.”


Markets in euro zone countries were sharply higher at the close. The Euro Stoxx 50 index, which covers an array of blue-chip companies in the euro zone, was up 5 percent.


Spanish and Italian bond yields have been dizzyingly high, reflecting the low confidence of investors in the recent period, but they slid on Friday to 5.8 percent for the Italian 10-year and 6.2 percent for the Spanish 10-year.


The yield on the benchmark 10-year Treasury yield was up to 1.65 percent, while the German 10-year was at 1.579 percent.


The dollar was lower, reflecting a weakness across a range of currencies. The euro rose sharply by about 2 percent to $1.266.


Crude oil prices climbed. Brent surged about 7 percent to $97.58 a barrel, while oil in New York trading soared 9.2 percent to $84.82.


European stocks, however, are mixed for the year so far, reflecting differences in vulnerability to the euro zone struggles. By the end of trading Friday, the German DAX was up more than 8 percent for the first half, while the Euro Stoxx 50 was down by about 2.2 percent.


Friday’s gain of 5.6 percent in the Spanish IBEX index failed to improve by much its year-to-date loss, which 17 percent through Friday. Investors have in recent months heavily sold the euro and moved out of European stocks. Some of those who had “shorted” those assets, that is, sold them on the expectation of being able to buy them back later at a profit, on Friday were buying buy back quickly to avoid losses.


Charles Diebel, head of market strategy at Lloyds Banking in London, attributed much of the action Friday to a “short-covering” rally.


“Given how low expectations were, it’s no surprise” that the markets are up, he said. “But it’s too early to say Europe’s saved.”


“It’s hard to say that this will be a game changer,” agreed Alessandro Frigerio, a fund manager at R.M.J. Sgr in Milan. “But this could be a good run.”


Mr. Frigerio said European banking shares had posted “brutal” gains almost across the board. An exception was Barclays, which agreed this week to pay more than $450 million to settle accusations that it had attempted to manipulate key interest rates.


Investors will now look for signs that the European Central Bank’s governing council, which has been reticent to act in the absence of movement on the political front, may now be ready to further support ailing euro zone governments.


Mr. Diebel said the E.C.B. could move as early as its next meeting, on Thursday, to cut its main interest rate target and possibly provide further liquidity to the financial markets, as it has done twice since late last year in its longer-term refinancing operations.


Philippe Gijsels, head of research at BNP Paribas Fortis Global Markets in Brussels, said much of the movement Friday reflected buying of riskier assets by investors who were caught off guard by the bank plan, but that Germany’s willingness to meet its European partners halfway suggested a turning point in the crisis might have been reached.


Lots of questions remain about Europe’s will to do what is necessary, he said, “but with what’s now on the table, and if the E.C.B. follows up, this could be the start of something.


“I’d call myself mildly positive,” he added.


Asian markets were also higher. The Hang Seng closed up just over 2 percent and the Nikkei rose 1.5 percent.