Citi said the settlement with the US Department of Justice and other government bodies resolves "substantially all" of its litigation on mortgages through 2008. The bank will take a $3.8 billion pre-tax charge to cover the settlement.
The huge charge dragged Citi's second-quarter earnings down 96 percent to $181 million, the bank said.
Under the mortgage settlement, Citigroup will pay $4.5 billion in cash and $2.5 billion in consumer relief. The cash component consists of a $4.0 billion civil penalty to the Justice Department.
Consumer relief includes financing for the construction of affordable rental housing and principal reduction.
Citi said the settlement will allow it to close the books on a messy set of civil claims.
"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 Citigroup chief executive Michael Corbat.
Besides the huge legal charge, Citi's second-quarter earnings were marred by an industry-wide drop in trading revenue that is also expected to hit JPMorgan Chase, Goldman Sachs and others when they report earnings later this week.
Those effects were offset by lower operating costs following corporate reorganizations, better credit quality and improved results in several categories of investment banking.
Excluding the legal settlement, Citi's results translated to profits of $1.24 per share, much better than the $1.05 projected by analysts. Including the legal charges, earnings were just three cents per share.
Revenues dropped to $19.3 billion from $20.5 billion a year ago. Analysts had projected revenues of $18.9 billion.
Citi shares rose 3.9 percent to $48.82 in pre-market trade.
The Citi settlement comes amid a broader US government fraud crackdown on large banks, and follows a similar $13 billion US mortgage deal with JPMorgan Chase. The government also is in talks with Bank of America about a potential settlement.
In recent weeks, the Justice Department has also extracted guilty pleas from French bank BNP Paribas and Switzerland's Credit Suisse for cases involving, respectively, violations of US economic sanctions and the enabling of tax evasion.