Citigroup Inc. struck a $7 billion deal to settle allegations it sold shoddy mortgages in the run-up to the financial crisis.

The bank said it will pay a total of $4.5 billion in cash and provide $2.5 billion in consumer relief. The cash portion consists of a $4 billion civil monetary payment to the U.S. Department of Justice and $500 million in compensatory payments to the state attorneys general and the FDIC.

Citigroup will take a charge of about $3.8 billion pretax in the second quarter. Those results are due at 8 a.m. EDT.

Citigroup's deal with the Justice Department comes after two and a half months of tense negotiating. Last month, the two sides were far apart on a potential deal, with the DOJ demanding $10 billion and Citigroup offering about $4 billion: a discrepancy big enough to nudge the Justice Department to threaten a lawsuit.

Citigroup was motivated to reach a settlement so it could wrap the resulting legal charges into second-quarter results. The bank didn't want to let the overhang of a settlement linger into another quarter, and it didn't want to be faced with a situation where it would have to restate its second-quarter results.