Warren Buffett will invest $5 billion in Bank of America Corp, stepping in to shore up the largest U.S. bank in the same way he helped prop up Goldman Sachs and General Electric during the financial crisis.

Bank of America shares rose nearly 26 percent at one point, but gave up most of those gains by early afternoon, closing 9.4 percent higher at $7.65. Trading was so heavy that, at one point midday Bank of America shares made up nearly 13 percent of the composite volume for the entire stock market.

Buffett and Bank of America said he made an unsolicited call to the bank on Wednesday morning offering to make an investment. Buffett told CNBC the idea came to him while taking a bath and the deal was done in 24 hours.

The deal entails Buffett's insurance company, Berkshire Hathaway Inc buying $5 billion of preferred shares and receiving warrants to buy 700 million shares. The warrants helped lift Berkshire Hathaway's paper profits on the deal to more than $3 billion, although the transaction has not yet closed.

The deal is expected to close on September 1 and includes provisions barring Buffett from raising his total BofA stake past 14.9 percent. Fully exercised, at the most recent share count the warrants represent a 6.5 percent stake.

Even though the bank has said it did not need to raise capital, investors widely believed it needed more money and to show it could raise funds easily. Employees were also relieved by the news. On at least one BofA trading floor, traders cheered when the news crossed the wires.

Bank of America has been plagued by fears that bad mortgage loans and legal liabilities from loans packaged into bonds by its Countrywide unit could drag it into tens of billions of dollars in fresh losses that would stretch its capital.

The deal proved again that Berkshire Hathaway has become something of a lender of last resort to the financial system, as when it invested in Goldman Sachs Group Inc and General Electric Co. Buffett's role in aiding the economy and the financial system has become symbolically important, given the lack of policy options left for the U.S. government and the Federal Reserve to stimulate demand.

This proves to the market that, if the bank needs additional capital, which we don't believe they do, but if they needed to calm the market by raising capital, they could do it within 30 minutes with a quick call to Uncle Warren, said Sean Egan, managing principal of Egan-Jones Ratings.

The deal comes at a cost for Bank of America. The $300 million of annual dividend payments it makes will cut into earnings per share and the deal will influence its outstanding share count.

Putting together these factors, analyst John MacDonald of Sanford C. Bernstein estimated the company's earnings per share will fall by roughly 5 percent for 2012 and 2013.

INSTANT RETURN

For Omaha-based Berkshire Hathaway, it is a better deal.

Berkshire gets warrants to buy 700 million shares of common stock at just over $7.14 per share, with an unusually long 10-year exercise period. One Berkshire holder said the warrants were by far the best part of the deal.

He could well make a 100 percent return on his investment in a few years, said James Armstrong, president of Henry H. Armstrong Associates. It's amazing how much a little hug from Buffett is worth these days.

Linus Wilson, an assistant professor of finance at the University of Louisiana at Lafayette, who has studied the pricing of warrants for large bank stocks, said warrants were worth $3.17 billion before the deal was announced, while the $5 billion of preferred shares were worth $4.46 billion, giving Buffett a total paper profit of $2.63 billion at the outset of the deal.

As the bank's shares soared, the profit on the position jumped.

Bank of America is selling to Berkshire 50,000 shares of cumulative perpetual preferred stock with a 6 percent annual dividend. The bank can buy back the investment at any time by paying Buffett 5 percent more than the face value of the securities.

It is virtually a mirror of the deal Berkshire did with Goldman in the depths of the financial crisis in fall 2008, except Goldman paid a 10 percent dividend and had a 10 percent redemption premium. The Goldman deal paid Berkshire $15 a second in dividends until Goldman bought out Buffett earlier this year.

It's a reasonably priced deal for Buffett. It's opportunistic, said Tom Russo, a portfolio manager at Gardner, Russo & Gardner who holds Berkshire shares.

As of June 30, Berkshire had 39 percent of its equity investments in the financial sector, according to Standard & Poor's.

BANK'S WOES

Earlier this month, a $10 billion lawsuit over soured mortgage securities by American International Group Inc helped spur fears about Charlotte-based Bank of America's liabilities, as well as questions about how it would pay for more losses.

In recent weeks, investors have sold the bank's shares, worrying that Bank of America might need more capital -- as much as $50 billion by some estimates -- to cope with losses and meet capital rules.

For shareholders who watched the bank take two government bailouts and saw the government step in earlier this year to block a planned dividend raise, further dilution would have been a bitter pill to swallow.

There is no expectation regulatory approval will be needed in this case, a regulatory official said.

CEO Brian Moynihan said on August 10 that the bank could add to its capital through earnings and asset sales. His remarks came two days after the bank's shares plunged 20 percent.

But many were not convinced. On Tuesday, blogger Henry Blodget said the bank could face $100 billion to $200 billion in write-offs and balance sheet issues, a claim the bank denied, but one that pushed its shares to early-2009 lows.

This helps with the credibility gap that I think has existed in the minds of some shareholders, said Jon Finger, managing partner of Finger Interests in Houston. Finger's family sold its bank to Bank of America years ago.

Moynihan has said the bank is targeting a 6.75 to 7 percent tier 1 common capital ratio by the end of 2013 under the new Basel III rules, which are designed to ensure big banks have enough capital to withstand crises large and small.

The cost of insuring Bank of America debt against default has risen, but it fell on Thursday after the Buffett deal, down 68 basis points to 305 basis points. That means it would cost $305,000 a year for five years to insure $10 million of debt.

(Reporting by Ben Berkowitz in New York and Joe Rauch in Charlotte; Additional reporting by Richard Leong, David Henry, Dan Wilchins, Joe Giannone, Jonathan Spicer, Clare Baldwin, Michael Erman and Lauren Tara LaCapra in New York, Scott Malone in Boston and David Clarke in Washington; Editing by Derek Caney, Robert MacMillan, John Wallace and Andre Grenon)