SAN FRANCISCO (MarketWatch) — Morgan Stanley and Bank of America Corp. ranked as top gainers among financial stocks Thursday as investors cheered an agreement reached by euro-zone leaders to bail out Greece and to have the region’s banks recapitalized.

Shares of Dow Jones Industrial Average component Bank of America Corp. BAC, +1.34% closed up 9.6%, while investment bank Morgan Stanley MS, +2.35% finished up 17%, as the best performing financial stock on the S&P 500.

The Financial Select Sector SPDR ETF XLF, +1.34% , which tracks the financial stocks in the S&P 500 Index SPX, +0.82% , added 6%, and the SPDR KBW Bank ETF KBE, +0.89% rose 5.1%.

While U.S. banks reportedly have little direct exposure to Greek debt, they would have suffered greatly from the effects on their exposed counterparties in Europe if Greece were to default.

Efforts to tame Europe’s sovereign-debt crisis that finally have borne fruit are doing much to restore confidence in the battered and volatile financial sector. Read more about the three-pronged agreement struck by European leaders.

“Ultimately, this is a big relief rally,” said Doug Roberts, chief investment strategist for Channel Capital Research.

Roberts said that many investors are revisiting their positions in financials and reconsidering going long for fear of missing out on low prices in the sector. Even with their gains Thursday, Bank of America’s shares are still down 46% on the year — the worst performance among the 30 stocks in the Dow industrials.

The rally, however, could be short-lived as details of the European plan come out or as investors’ focus turns back to what the congressional budget supercommittee does or doesn’t do, according to Roberts. Read more on the supercommitee’s latest public session.

Also Thursday, shares of Ameriprise Financial Inc. AMP, +2.48% rallied 13%, after the firm reported third-quarter results late Wednesday. Sterne Agee & Leach also raised its price target on the stock, citing higher-than-expected buybacks and a strong capital position.

Other notable gainers included Citigroup Inc. C, +1.62% and Moody’s Corp. MCO, +1.44% , which both finished up more than 9%. Shares of Goldman Sachs Group Inc. GS, +2.12% closed up 9.5%.

The other three financial components of the Dow industrials also fared well: J.P. Morgan Chase & Co. JPM, +0.96% added 8.3%, while Travelers Cos. TRV, +0.69% rose 3.3% and American Express Co. AXP, +2.55% gained 3.2%.

Recently reported third-quarter profits were bolstered by the release of money from reserves that previously had been set aside to cover bad loans. Banks also got a profit boost from an accounting adjustment tied to debt obligations.

Loan growth was uneven and trading revenue got hammered by regulatory restrictions, with a lack of merger deals and new stock offerings proving a further hindrance for banks.