Countrywide Financial Corp on Wednesday received a $2 billion injection from Bank of America Corp, helping the largest U.S. mortgage lender shore up its finances as it struggles with a liquidity crunch.

Bank of America, the second-largest U.S. bank, said it bought non-voting preferred stock that yields 7.25 percent and can be converted into Countrywide common stock at $18 per share, 17.5 percent below the shares' Wednesday closing price. Countrywide shares soared 20 percent in after-hours trading.

It's a $2 billion vote of confidence from a major financial institution, said Steve Persky, a portfolio manager at Dalton Investments in Los Angeles. Are we out of the woods yet in the mortgage market? No.

Sean Egan, managing director of independent credit rating firm Egan-Jones Ratings Co, said the investment is a large positive in the sense that it bolsters confidence and enhances liquidity.

However, based on recent results at other mortgage firms, Countrywide will probably need some additional capital to plug the hole, he added. Countrywide is going to have to shrink its business. Its wings have been clipped.

The investment came six days after Countrywide stunned investors by tapping an entire $11.5 billion credit line because it was having difficulty selling short-term debt.

This raised concerns about how well the Calabasas, California-based company could navigate the credit crisis afflicting a wide range of U.S. lenders. At least two analysts said bankruptcy was possible if market conditions worsened.

Countrywide made 17.4 percent of U.S. mortgage loans from January to June, according to newsletter Inside Mortgage Finance. Charlotte, North Carolina-based Bank of America ranked fifth, with a 6.7 percent share.

In the current turmoil, the stock market has been underestimating the value in Countrywide's operations and assets, Bank of America Chief Executive Kenneth Lewis said in a statement. We hope this investment will be a step toward a return to more normal liquidity in the mortgage markets.

Countrywide's market value was about $12.6 billion as of Wednesday's close. Its shares closed up 3 cents at $21.82 in regular trading, and soared to $26.19 after hours. Bank of America shares closed up 35 cents to $51.65 in regular trading, and rose to $52.50 after hours.

MORTGAGE PROBLEMS NOT OVER

Prior to the investment, Countrywide shares had fallen 49 percent this year as delinquencies and foreclosures increased, leading to a shortage of credit needed to make new home loans.

Worries about Countrywide's health led many customers at its bank unit to withdraw money, including deposits that were federally insured. On Monday, Countrywide placed advertising in several newspapers to assure depositors their money was safe.

Angelo Mozilo, Countrywide's chief executive, said the Bank of America investment helps position the company he helped found for future growth.

Analysts said Countrywide still faces a struggle, now that credit worries over riskier subprime borrowers have spread into other markets.

The impetus behind Bank of America's investment, and the bank's longer-term goals, were not immediately clear. The investment follows the U.S. Federal Reserve's surprise decision on Friday to cut what it charges banks to borrow, and perhaps help boost liquidity in the financial system.

In January, before the mortgage crisis surfaced, Lewis said we're not particularly interested in the wholesale and correspondent business, in response to speculation the bank might buy or enter a joint venture with Countrywide.

Eventually I think they'd be looking to acquire the whole firm, said Ganesh Rathnam, an analyst at Morningstar Inc in Chicago. I don't see why they would otherwise buy $2 billion into it.

Bank of America probably could not acquire Countrywide outright for a while. The bank's pending acquisition of LaSalle Bank Corp from ABN AMRO Holding NV would push it up against a 10 percent federal cap on deposits.

Goldman Sachs & Co and law firm Wachtell, Lipton, Rosen & Katz advised Countrywide on the transaction. Bank of America was advised by its own investment bankers and law firm Cleary Gottlieb Steen & Hamilton LLP.

(Additional reporting by Anupreeta Das, Christian Plumb, Chris Sanders and Dan Wilchins)