Citigroup has agreed to pay $7bn (£4.1bn) to settle a US investigation into shoddy mortgage-backed securities the bank sold in the run-up to the financial crisis, including the largest civil fraud penalty ever levied by the US Justice Department.