WASHINGTON — Wells Fargo 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.

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.

Unlimited Digital Access. $1 for 4 weeks.

The firms bundled the mortgages into securities and could try to force banks to buy back loans that did not meet certain guidelines.

Banks have agreed to pay Fannie about $12.7 billion this year to resolve disputes over toxic mortgages.

The largest deal was a $10.3 billion settlement with Bank of America in January.