Westlake Financial Services and American Credit Acceptance will pay $7.4 million to Massachusetts car buyers after the state’s attorney general said the lenders charged consumers excessive interest rates on subprime loans.

The lenders last week agreed to eliminate interest rates on loans that Massachusetts Attorney General Maura Healey said have higher rates than permissible. The lenders will also reimburse consumers for the interest they have already paid.

Massachusetts law says that retail installment contracts may include GAP but charges for GAP must be included in the finance charge when determining whether the contract exceeds the 21 percent rate cap.

Westlake Financial, a predominantly subprime and near-subprime lender in Los Angeles owned by Hankey Group, will pay $5.7 million in relief to affected borrowers. From 2012 to 2015, Westlake Financial purchased more than 2,100 loans with an interest rate above 21 percent in Massachusetts, according to the assurance of discontinuance, which is similar to a settlement.

American Credit Acceptance, a subprime lender in Spartanburg, S.C., will pay $1.7 million in relief. From 2013 to 2015, American Credit Acceptance purchased more than 150 auto loans with an interest rate above the cap, according to the legal documents.

“There are protections in place to ensure that consumers who take out auto loans are treated fairly and not forced to pay illegal and excessive interest rates,” Healey said in a statement. “Our office will continue to make sure that these protections under state law are applied properly so that consumers are not exploited by predatory practices.”

Last year, before the attorney general investigation, Westlake Financial and American Credit Acceptance discontinued the purchase of any Massachusetts retail installment contract with financed GAP to ensure compliance with state law.

American Credit Acceptance and Westlake Financial had no comment on the agreement.