National Grid will pay millions of dollars to settle claims that the utility improperly charged customers who were unable to pay their bills, after an investigation by Attorney General Maura Healey’s office.

“Customers already struggling to heat their homes were hit with illegal charges by their gas company,” Healey said yesterday in a statement. “This agreement with National Grid returns millions of dollars to more than 50,000 customers.”

According to Healey’s office, National Grid charged tens of thousands of customers $50 to reconnect residential natural gas service after it had been shut off for nonpayment between November 2010 and November 2016, despite agreeing to eliminate the fee. Healey’s office said 53,000 customers were charged, including more than 3,000 low-income customers who were charged the fee multiple times. One customer was improperly charged the $50 fee 13 times, Healey’s office said.

National Grid said the fees were the result of a programming error, and said it has already refunded some customers.

“National Grid has corrected the programming error and to date has refunded $1.6 million in the form of credits to 31,647 customers,” the company said in a statement. “The Company has attempted to contact the remaining 45,100 former customers, but has been unable to locate them.”

National Grid said it will create a restitution fund of $2.2 million for customers it has been unable to locate. The company will also pay $3 million to Healey’s office that will be used to help customers pay or lower their gas bills; $180,000 to the state’s general fund; and $20,000 to cover the cost of the attorney general’s office’s investigation.