Ofcom said customers were left "out of pocket".
The regulator said around 400,000 EE customers who ended their contracts early were over-billed and paid up to £4.3m too much as a result.
It added almost 82,000 Virgin customers were overcharged by just under £2.8m. However, Virgin said it would appeal.
Gaucho Rasmussen, director of investigations and enforcement at Ofcom, said: "EE and Virgin Media broke our rules by overcharging people who ended their contracts early. Those people were left out pocket and the charges amounted to millions of pounds."
Fine 'not justified'
The fine for Virgin Media was £7m, Ofcom said, with an additional £25,000 for providing incomplete information to the regulator.
Ofcom found that Virgin Media had levied early-exit charges that were higher than customers had agreed to when signing up to their residential contracts. The regulator said this went on for almost a year.
However, Virgin Media said it "strongly disagrees" with Ofcom's decision and would appeal to the Competition Appeal Tribunal.
"This decision and fine is not justified, proportionate or reasonable. A small percentage of customers were charged an incorrect amount when they ended one or more of their services early and for that we are very sorry," said Tom Mockridge, chief executive of Virgin Media.
Virgin Media said it had mistakenly overcharged 1.5% of its 5.5 million cable customers between September 2016 and August 2017.
The company has reimbursed or made charity donations covering 99.8% of its overcharging.
Customers yet to be repaid
EE apologised to customers after it was fined £6.3m following Ofcom's discovery that over a six-year period the firm did not set out the charges its mobile customers would have to pay if they left their contracts early.
Ofcom said that up to 15 million EE customers faced being over-billed by up to £13.5m as the company had miscalculated early-exit charges. However, not all affected customers had paid these excessive charges as EE had subsequently waived some of them, leaving £4.3m in excessive charges.
A spokesperson for EE said: "We've already refunded customers and changed the way we calculate early termination charges, and we will continue to focus on ensuring our policies are clear and fair for all customers."
However, Ofcom said that £1.6m of the £4.3m of the overcharged fees were yet to be repaid as EE did not have records covering the whole period. Customers who feel they may have been overcharged should contact EE.
Ofcom said the behaviour of both companies made customers less likely to switch provider, which was against its rules.