NEW YORK (CNNMoney.com) -- Troubled Colonial BancGroup will be bought by rival BB&T Friday, the government said after state regulators closed the bank whose assets had been frozen by a federal judge.

The Montgomery, Ala., bank, which has 346 branches spread across Florida, Alabama, Georgia, Nevada, and Texas,is the sixth largest bank failure in U.S. history and by far the largest failure of 2009.

With $25 billion in assets and $20 billion in deposits, Colonial is 100 times larger than the typical bank to have failed this year.

BB&T (BBT, Fortune 500) will buy $22 billion of Colonial's assets, as well as its deposits and branches, leaving the remaining assets in the hands of the Federal Deposit Insurance Corp.

BB&T, based in Winston-Salem, N.C., is also a regional banking power, with 1,500 branches across the Southeast. It is also a major mortgage lender.

Most customers of Colonial should not be affected by the closing. The FDIC, the federal agency that has protected bank deposits since the Great Depression, will guarantee account balances up to $250,000.

But home buyers and those who want to refinance their mortgages could end up paying somewhat higher rates, even if they have never heard of Colonial, said Guy Cecala, publisher of trade publication Inside Mortgage Finance.

Cecala said Colonial was a significant player in the sector of the business known as "mortgage warehouse" lending, which provides financing needed by mortgage brokers and non-bank lenders to make home loans.

"The more firms like this that get out, the more dependent we get on large banks, and less competition there is. That's never a good thing," he said. Warehouse lending used to be a huge source of funds for home loans, according to Cecala, but the mortgage defaults and declining home prices of recent years has decimated the business.

"The warehouse lending market is now so fragile and so small, it doesn't help when we lose anybody," he said. "We have only a cup of water where we used to have a bucket of water."

Trust fund hit: The failure of Colonial is another blow to the FDIC trust fund, which has had to cover 77 bank failures so far in 2009 -- including four more late Friday (see below).

The fund took a $35.1 billion hit in 2008, and an additional $4.3 billion decline in the first quarter of this year, leaving it with assets of only $13 billion as of March 31. But most of last year's decline was due to $25 billion the agency set aside to cover future losses.

"The past 18 months have been a very trying period in the financial services arena," said FDIC Chairman Sheila Bair, in the Colonial failure release. "Our industry funded reserves have covered all losses to date. In fact, losses from today's failures are lower than had been projected.

Little more than a year ago, bank failures were relatively rare, with only four occurring in the first six months of last year. The collapse of IndyMac, a major mortgage lender, in July 2008, signaled a rash of failures to follow. IndyMac cost the FDIC about $10.7 billion by itself, and is the most expensive failure in history.

Colonial will likely be one of the most expensive bank failures, according to Chip MacDonald, a banking lawyer at Jones Day, given its active position in mortgage warehouse lending across the Southeast.

The FDIC said Colonial's closing will cost the Deposit Insurance Fund $2.8 billion. "That's a significant share of the FDIC fund," he said.

It is now a rare Friday night that the agency does not seize the assets of a newly failed bank. And the number of banks judged as troubled has soared to 305 as of March 31, up from only 90 a year earlier. Those 305 problem banks on the FDIC's confidential list have combined assets of $220 billion.

The trust fund that covers the deposits is paid by banks, and the weaker banks have seen those premiums rise about 14% in the last year. The agency has also announced a special one-time assessment on bank assets that will raise $5.6 billion for the fund this September. But those funds will come from money that the banks will not lend out to businesses and consumers in hopes of reviving the economy.

Legal problems: MacDonald said that Colonial is also unusual because of the allegations of criminal wrongdoing at the bank.

Colonial disclosed on Aug. 4 that federal agents had executed a search warrant at its mortgage warehouse lending offices in Orlando, Fla. It also had been forced to sign a cease and desist order with the Federal Reserve and regulators at the end of last month related to its accounting practices and recognition of losses, which limited its abilities to make dividends or other payments to investors.

The agents who searched its offices came from the Special Inspector General for the Troubled Asset Relief Program, even though Colonial never received TARP funds.

Colonial applied for TARP assistance but had been told it needed to be able raise an additional $300 million in private capital to be eligible for the federal assistance. On March 31 Colonial announced it had found such an investor in Taylor, Bean & Whitaker Mortgage Co., a major non-bank mortgage lender based in Florida. But that deal collapsed, and TBW halted operations on Aug. 5 as its offices were also searched by federal agents.

The bank had issued a statement to investors in November saying it had applied for TARP and had no reason to believe its application was being processed through the normal channels. After it later disclosed the need to raise the additional $300 million in capital to get TARP, it was hit by a shareholder suit.

Colonial could end up as the second-most expensive bank failure, according to Chip MacDonald, a banking lawyer at Jones Day, given its active position in mortgage warehouse lending across the Southeast.

"It's probably going to be cheaper than IndyMac, but my guess is it could be $5 billion to $7 billion," he said. "That's a significant share of the FDIC fund."

The sale of Colonial to BB&T also comes a day after U.S. District Judge Adalberto Jordan ruled in favor of Bank of America (BAC, Fortune 500), which had requested a temporary restraining order to keep Colonial from liquidating or transferring assets worth $1 billion.

"Viewing Colonial's contractual breach in conjunction with the fact that Colonial is on the brink of collapse and is suspected of criminal accounting irregularities, the potential for immediate substantial injury to Bank of America is clear," the judge said in his order.

The lawsuit that prompted the order was filed by Bank of America. It involved more than 6,000 mortgages issued by its subsidiary and held in trust by Colonial. According to the motion, Bank of America is owed more than $1 billion in assets, but Colonial had failed to pay the amount owed.

Last month, the bank said in a statement that it had "substantial doubt about Colonial's ability to continue" due to uncertainties about its ability to increase its capital levels.

Shares of Colonial (CNB), which fell 80% in 2009, were not trading Friday. But shares of BB&T (BBT, Fortune 500) gained nearly 9% on the report of the acquisition.

Four other banks fail: Late Friday, the FDIC also said that four other banks had failed. Outside of Colonial, the largest collapse of the day was Community Bank of Nevada in Las Vegas, which went under with assets of $1.52 billion and total deposits of about $1.38 billion. Its failure will cost the FDIC's Deposit Insurance Fund an estimated $781.5 million

The Nevada bank did not find a buyer, leaving the FDIC in control of its assets. The agency immediately created a new institution, the Deposit Insurance National Bank of Las Vegas, which will remain open for approximately 30 days to allow depositors access to their insured deposits and give them time to open accounts at other insured institutions. Banking activities, such as direct deposit, writing checks, and using ATM and debit cards, will continue normally through the transition.

Dwelling House Savings and Loan Association in Pittsburgh closed its door for the last time Friday. The FDIC said PNC Bank will assume control of its assets. It was the first Pennsylvania bank to fail this year.

As of March 31, Dwelling House held assets worth $13.4 million and total deposits of $13.8 million. The FDIC estimates that this closure will cost the its insurance fund $6.8 million.

MidFirst Bank of Oklahoma City assumed all deposits of two failed Arizona banks, Union Bank in Gilbert and Community Bank of Arizona in Phoenix. Community Bank of Arizona had assets of $158.5 million and total deposits of approximately $143.8 million. Union Bank had assets of $124 million and total deposits of approximately $112 million.

The two failures, the first in Arizona this year, will together cost the FDIC's insurance fund around $86.5 million.

The 77 bank failures so far in 2009 has more than tripled last year's total of 25.