WASHINGTON — Wells Fargo & Co. said Monday that it agreed to pay $591 million to Fannie Mae to settle disputes over soured mortgages that the bank sold to the seized housing finance giant during the subprime housing boom.

The agreement covers loans originated by Wells Fargo before 2009 that Fannie Mae was trying to force the bank to buy back. The deal “resolves substantially” all repurchase issues related to those loans, the company said.

Wells Fargo will pay $541 million in cash to Fannie Mae, with the rest covered by credits from earlier repurchases.

Fannie Mae and its sibling firm, Freddie Mac, were seized by the federal government in 2008 as they teetered near bankruptcy because of bad loans they had purchased from banks. The firms bundled the mortgages into securities and could try to force banks to buy back loans that did not meet certain guidelines.

Fannie Mae and Freddie Mac have been aggressively pushing banks to repurchase so-called legacy loans the firms had bought before they were placed under government conservatorship.

In October, Wells Fargo agreed to an $869 million settlement with Freddie Mac on pre-2009 mortgages.