Scotland's top law officer has claimed the Crown Office was "repeatedly misled" by the Post Office over prosecutions linked to the Horizon system.
Lord Advocate Dorothy Bain KC appeared before MSPs at Holyrood on Tuesday afternoon.
Ms Bain had been called to clarify when the Crown Office knew about the flawed system, which may have resulted in up to 100 sub-postmasters and sub-postmistresses north of the border being wrongly convicted of embezzling money.
Prosecutions were handled by the Crown Office in Scotland, not the Post Office.
In a statement, Ms Bain said: "I am very deeply troubled by what has occurred, and I remain acutely concerned that the Crown Office and Procurator Fiscal Service was repeatedly misled by the Post Office.
"Assurances, which were just not true, were repeatedly given.
"To those wrongfully convicted, I understand your anger and I apologise for the way that you've been failed by trusted institutions and the criminal justice system. And I stand beside you in your pursuit of justice.
"I want to assure this chamber, those wrongly convicted, and the people of Scotland that I will do all I can to prevent such an affront to our justice system from ever happening again and to right the wrongs which have occurred."
The Crown Office previously confirmed it first found out about issues with the system in May 2013.
In August that year, guidance was issued to prosecutors urging them to ensure cases were not overly reliant on Horizon evidence.
The lord advocate claimed between 2000 and 2013, there was no record of prosecutors having been made aware of issues with the Horizon system.
When concerns were discussed in September 2013, Ms Bain said Post Office officials "repeated their assurances to Scottish prosecutors".
After the Post Office failed to deliver expert evidence and a further report to support the integrity of Horizon in the months that followed, the Crown Office took the decision to take no further prosecutorial action in several newly reported cases.
During another meeting in October 2015, Post Office officials once again said they "remained confident" in Horizon.
However, prosecutions were thereafter effectively dropped after the Post Office confirmed it was unable to provide a final expert report or evidence supporting the integrity of Horizon.
Ms Bain said: "During this period, the Post Office did not disclose to Scottish prosecutors the true extent of the Horizon problems as they are now known to be.
"Scottish prosecutors received assurances that the system was robust.
"These were assurances that prosecutors, without the benefit of hindsight, were entitled to take at face value.
"They would not have known, nor indeed suspected, that the Post Office may not have been revealing the true extent of the Horizon problems.
"Because of the failures by the Post Office, we know that a number of people in Scotland may have suffered a miscarriage of justice."
The lord advocate claimed that the Post Office "failed in its duty of revelation" when reporting cases to the Crown Office.
Ms Bain added that when it became clear that Post Office explanations "could no longer be relied upon", prosecutors changed policies, dropped cases and subsequently supported the work of the Scottish Criminal Cases Review Commission (SCCRC), the Court of Appeal in Scotland, and the UK public inquiry.
She said that in September 2020, the SCCRC wrote to 73 individuals who may have been convicted in Scotland on the basis of "unreliable evidence" from the Horizon system.
To date, 16 people have come forward to have their cases reviewed. Ms Bain said seven referrals have been made to the high court, four of which have resulted in convictions being overturned.
In addition, she said the Crown Office had identified "potentially affected cases" in order to ensure that "no possible miscarriage of justice is missed".
As a result of this, 54 cases are being considered by prosecutors as potential Horizon cases, with Ms Bain adding that most of these people had already been written to by the SCCRC.
The lord advocate said: "It will be noted that, of those written to, only a small portion of people have come forward to identify themselves as possibly affected.
"This may be indicative of the fact that not every case in which Horizon evidence is present will represent a miscarriage of justice."
Ms Bain apologised to all those affected and pledged transparency going forward, subject to restrictions in regard to ongoing appeals and the public inquiry.
The Post Office has been contacted for comment.