British Gas has paid £2.65m in refunds, compensation and redress after wrongly overcharging more than 94,000 customers who switched to new providers.
According to the regulator Ofgem, British Gas charged customers its more expensive standard variable tariff rate after they decided to switch to a new supplier, due to a system error.
British Gas also wrongly charged exit fees to 1,698 fixed deal customers.
It also wrongly informed 2.5 million customers they might incur an exit fee.
British Gas said following the system error, those who were charged too much were "promptly refunded as soon as we identified the issue and were paid an additional goodwill gesture".
It said some customers were provided with initial communications containing incorrect terms and conditions - but all other communications they received were correct. "We have changed our processes to ensure the error has been corrected," it added.
Anthony Pygram, director of conduct and enforcement at Ofgem, said: "British Gas failed its customers who were coming to the end of their fixed contracts and switched supplier by unfairly penalising them and applying charges in error.
"Many more customers could have been deterred from getting a better deal due to the incorrect terms and conditions."
Those customers who were switched to a more expensive British Gas standard variable rate tariff, after they decided to switch to a new supplier, were overcharged by a total of £782,450, according to Ofgem.
Meanwhile, the total of the incorrect exit fees charged to the 1,698 affected fixed deal customers totalled £64,968.
Ofgem's investigation found that British Gas had provided 2.5 million customers with incorrect terms and conditions, which stated that exit fees were payable during the 49 day period before their fixed deals expired.
Under industry conditions, a customer is generally entitled to switch at any time during or after this "switching window" without having to pay an exit fee.
Ofgem said this switching window was designed to encourage customers to switch to a better deal before they were rolled onto a default tariff at the end of their contract.
The regulator opened an investigation in July 2017 following concerns raised by website MoneySavingExpert.com.
Before the investigation had been completed, British Gas refunded in full all customers who had been overcharged by more than £1 and paid £502,633 in compensation to them.
Following Ofgem's findings, British Gas agreed to pay a further £244,770 in compensation to customers wrongly charged exit fees, and also paid £1,050,229 into Ofgem's consumer redress fund.
The redress scheme is a pot of money open to charitable organisations that support energy customers in England, Scotland and Wales. Charities can apply for cash to carry out schemes such as making homes more energy efficient.
Energy firms can pay into the fund in lieu of, or in addition to, a financial penalty for breaches of their licence conditions.