The Post Office will pay almost £58m to former subpostmasters over an IT system which allegedly led to some going bankrupt and others being prosecuted for offences like fraud.
More than 550 people brought the group case over the Horizon IT system, introduced between 1999 and 2000.
They said the system had numerous software problems which caused shortfalls in their accounts.
The first of at least three trials over the case finished in March, with a judge resolving most issues in favour of the subpostmasters.
Legal fees had already reached £10m before that trial.
But following mediation, the case has been settled.
Alan Bates, one of six lead claimants representing the group, thanked the Post Office’s new chief executive, Nick Read, for his “leadership, engagement and determination” in helping bring the case to an end.
“During the mediation, it became clear that he intends to reset the relationship between the Post Office and its subpostmasters and put in place new processes and support for them, as part of a wider programme of improvements,” said Mr Bates.
The subpostmasters claimed the Post Office had not trained them properly in the IT system and that they were misled over its reliability.
They also accused it of failing to investigate the cause of the alleged shortfalls.
Some of those affected told Sky News how they fell into depression and felt as if “I had a gun to my head” after being accused of stealing.
The Post Office insisted the Horizon system worked properly and defended the case.
However, in a statement after the settlement was announced, Post Office chairman Tim Parker admitted that “in the past, we got things wrong in our dealings with a number of postmasters”.
He added: “We look forward to moving ahead now, with our new chief executive currently leading a major overhaul of our engagement and relationship with postmasters.”
New Post Office chief executive Nick Read, who started his job in September, said he was “very pleased” that the two sides had been able to agree a settlement.
“Our business needs to take on board some important lessons about the way we work with postmasters, and I am determined that it will do so,” he said.
“We are committed to a reset in our relationship with postmasters, placing them alongside our customers at the centre of our business.”