J.P. Morgan Chase & Co. agreed to pay $4.5 billion to investors seeking to recover losses from mortgage-backed securities sold before the financial crisis, the latest attempt by the largest U.S. bank to put its legal woes behind it.

The group, composed of 21 high-profile institutional investors including BlackRock Inc. and Allianz SE's Pacific Investment Management Co., previously received an $8.5 billion settlement from Bank of America Corp. on similar claims. It had been seeking as much as $5.75 billion to settle...