Citigroup agreed to pay $7 billion to settle charges that it packaged bad mortgages during the run-up to the financial crisis.

It includes $4 billion in penalties, $2.5 billion in mortgage modifications and other relief to homeowners, and $500 million going to five states and the Federal Deposit Insurance Corp.

The settlement means Citi will be able to avoid a civil suit by the Justice Department and mirrors similar agreements with JPMorgan Chase (JPM) and other lenders in recent years.

While Citi took a $3.8 billion hit because of the deal, which essentially wiped out its earnings for the quarter, it can afford it. Last year, the bank earned $14 billion and had $35 billion of cash on its balance sheet as of June 30.

Attorney General Eric Holder said Citigroup misled investors about the quality of risky mortgages it bundled into securities during the housing boom, allowing it to increase profits and market share.

"Under the terms of this settlement, the bank has admitted to its misdeeds in great detail. The bank's activities shattered lives and livelihoods throughout the country," he said. "They contributed mightily to the financial crisis that devastated our economy in 2008.

Shares of Citi (C) rose more than 3% in midday trading.

What it means for homeowners:

Some homeowners with Citi mortgages could see the amount of their loans reduced, or could have their interest rates reduced. There will also be down payment and closing cost assistance to future homebuyers.

In addition, Citi financing will be provided for affordable apartments, which could help to keep rents low and make donations to various community organizations. But details of terms of the help and how many will benefit are not yet known. Associate Attorney General Tony West said the relief called for in the deal could benefit hundreds of thousands of homeowners.

"The reality is that for substantial numbers of people, we will not be able to make them whole," said Holder.

Citi only agreed to provide that help by the end of 2018.

Why Citi agreed to the deal:

The bank has been under increasing pressure from regulators. The Federal Reserve gave Citigroup a poor grade in its stress test in March and blocked its plans to return money to shareholders through buying back shares and increasing the dividend.

Citi is also under investigation for possible fraud and money laundering in its Mexican unit. All of that has been a drag on its stock.

"We believe that this settlement is in the best interests of our shareholders, and allows us to move forward and to focus on the future, not the past," said Citi CEO Michael Corbat.

The amount is far more than the $363 million initial offer from Citi (C) but less than the $12 billion initially sought by Justice, according to a source familiar with the deal. Holder confirmed reports that the Justice Department was prepared to file a civil suit against Citi when the bank agreed to the larger settlement amount.

Other bank settlements:

Citi's agreement is just the latest by the bank that has now paid $12 billion in fines and settlements related to the mortgage loans it sold to investors ahead of the crisis. Citi's $4 billion civil penalty, which will go to the Treasury Department's general fund, is the largest civil fine of its kind. That fine will not be tax deductible, according to Assistant Attorney General West.

The latest deal is about half the $13 billion JPMorgan Chase agreed to pay last November, although that deal only included $2 billion to the Justice Department.

JPMorgan's deal also included payments to government-controlled mortgage lenders Fannie Mae and Freddie Mac, as well other regulators not included in the Citi deal. Citi's settlement is also smaller than a $9.5 billion settlement that Bank of America (BAC)reached in March with Fannie's and Freddie's regulator.

Bank of America remains in talks with the Justice Department on a separate mortgage settlement with that agency, but government lawyers and the bank remain billions of dollars apart, according to law enforcement sources.