Wells Fargo said Wednesday it had agreed to pay $335 million to settle claims by Fannie Mae and Freddie Mac that it overstated the quality of mortgage securities it sold them. The US bank said the two state-controlled housing finance agencies had agreed to the sums having earlier pulled out of a class-action suit against it for overstating the quality of mortgage-backed securities it marketed in the run-up to the 2008-2009 financial crash. The settlement involved the Federal Housing Finance Agency, the conservator for the two agencies, Wells Fargo said in a securities filing. The government was forced to rescue the two agencies during the crisis, which was marked by an implosion in the housing market that delivered huge losses to holders of trillions of dollars worth of securities backed by what turned out to be low-quality subprime mortgages.