Wells Fargo & Co. will pay $575 million to settle state-level claims over the bank’s sales practices.

The settlement with 50 states and the District of Columbia announced Friday resolves state investigations into Wells Fargo’s practices from 2002 to 2017. The practices, which have previously been disclosed, include opening bogus accounts, charging improper mortgage rate-lock extension fees, and forcing insurance policies on auto-lending customers.

“Wells Fargo is paying over half a billion dollars to the states because of conduct that caused widespread harm on a national level, in bank accounts, auto loans, and mortgages,” said Pennsylvania Attorney General Josh Shapiro in a statement. “This bank opened millions of accounts for customers who didn’t know about them, charged auto-finance customers for insurance policies they didn’t want or need, and charged mortgage customers over $100 million in unwarranted fees. With this settlement, we are holding Wells Fargo accountable and changing corporate conduct to protect consumers.”

Wells Fargo’s expenses surged over the past two years, driven by fines and legal costs as investigations into its consumer businesses multiplied. The scandal erupted in 2016 with the revelation that bank employees opened as many as 3.5 million accounts without customer approval in order to meet sales goals.

“Wells Fargo’s corporate culture led to repeated breaches of its customers’ trust,” said N.J. Attorney General Gurbir Grewal in a statement. “This settlement should send a message to all financial institutions that they need to take steps to avoid similar consumer-protection violations, because we stand ready to hold the financial industry accountable.”

The bank said in a statement that it had already set aside $400 million for the settlement and would take a $175 million provision in its fourth-quarter results. The company reached a $1 billion settlement with federal regulators earlier this year over some of the issues.

“This agreement underscores our serious commitment to making things right in regard to past issues as we work to build a better bank,” chief executive officer Tim Sloan said in the statement.