Thousands of criminal cases could be open to appeal after a Supreme Court ruling that Scots police can no longer question suspects without their lawyer.
Judges in London upheld an appeal by teenager Peter Cadder, whose assault conviction was based on evidence gained before he spoke to his lawyer.
Until now suspects could be questioned for six hours without a lawyer present.
The judges ruled this violated human rights to a fair trial. Ministers now plan to change Scots law.
The Supreme Court judges said it was "remarkable that, until quite recently, nobody thought that there was anything wrong with this procedure" of questioning suspects without their lawyer present.
They ruled it contravened a decision by the European Court of Human Rights in 2008 that suspects having access to a lawyer was fundamental to them receiving a fair trial.
In their ruling, the judges admitted that their unanimous decision would have "profound consequences" for many Scottish cases.
But they said: "There is no room, in the situation which confronts this court, for a decision that favours the status quo simply on grounds of expediency.
"The issue is one of law. It must be faced up to, whatever the consequences."
It is thought the judgement could increase the Scottish legal aid bill by up to £4m.
It could also pave the way for other similar convictions to be reviewed or appealed.
In the court's 47-page judgment it said up to 76,000 cases were ongoing or awaiting trial, although not all would be affected by their decision.
The vast majority of them were summary cases, which are now time-barred from appeal and the Supreme Court made it clear its ruling would not apply to closed cases.
The Crown Office estimated the number of possible appeals at closer to 3,500.
It said a total of 120 solemn cases were affected by the judgement.
Among them could be Luke Mitchell, who was just 14 when he was questioned without a lawyer by police investigating the murder of his girlfriend, Jodi Jones.
That aspect of his case is already being investigated by the Scottish Criminal Cases Review Commission.
The judges' decision has prompted the Scottish government to introduce emergency legislation to bring the country's rules into line with European human rights laws.
Justice Secretary Kenny MacAskill said it had created a situation "to which we must respond".
"With parliament's support we will be making swift legislative changes to protect the victims of crime and safeguard communities," he said.
"The main changes will mean introducing a right of access to legal advice before being questioned, extending the period during which a person may be detained, powers to adjust legal aid eligibility rules and measures to ensure certainty and finality in concluded cases.
"We will be introducing this emergency legislation to parliament on Tuesday and with the support of the other political parties we can complete the parliamentary scrutiny and debate process during the course of Wednesday. We anticipate the bill receiving Royal Assent by Friday."
Mr MacAskill said the Supreme Court's decision had overturned "decades of criminal procedure in Scotland".
He also said it had "gone against the unanimous decision last October by seven Scottish High Court judges at the Scottish Appeal Court".
The justice secretary added: "We are concerned that the current devolution arrangements have created an anomaly that seems to put Scottish law at a disadvantage in comparison to elsewhere in the EU.
"I want to see steps taken to address this anomaly."
Mr MacAskill said that the Supreme Court ruling had been "anticipated and planned for".
The Crown Office recently ordered lawyers to be allowed immediate access to arrested clients.
The Lord Advocate Elish Angiolini said the ruling had "significant implications" for Scots law.
"Prosecutors work within the law made by parliament and as interpreted and stated by the courts," she said.
"Today's ruling in Cadder changes understanding of the law...and so we will immediately adapt our working practices to this new legal landscape."
Prof Alan Miller, chair of the Scottish Human Rights Commission, said: "This is no time for emergency legislation as there is no emergency.
"The floodgates have not been opened - this decision clearly does not apply to concluded cases.
"Rather, now it's time to get it right, and we have the time to get it right."
He said warned that the government's timetable for emergency legislation was too short to allow a "considered response".
Mr Miller added: "The proposed extension of the six hour time limit for detention on reasonable suspicion to 12 and then possibly 24 hours at the discretion of the police seems a disproportionate response to a decision which was based on the need to recognise the vulnerability of those questioned in police detention."
Liberal Democrat justice spokesperson Robert Brown said his party had "substantial reservations" about the emergency legislation proposed by the Scottish government.
He said: "There will be no detailed consideration of these important changes by the Justice committee and negligible chance for public input.
"We have reluctantly agreed to the process but we will be pursuing amendments to tighten up the procedures.
"Whilst the law needs to be changed to accommodate the judgement, I have concerns about the proposal to extend the period of detention from six hours to 24 hours, effectively at the discretion of the police."
Labour's justice spokesman Richard Baker said there could be increases to the legal aid budget and changes to the detention of suspects.
He said: "Also, the cornerstone of Scottish justice itself, which is the corroboration of evidence, will need to be examined."
Mr Baker said Labour would work with the Scottish government to ensure that any legislative changes to the justice system were made quickly.
Conservative justice spokesman John Lamont described the ruling as "devastating" and said that the "whole operation of the European Court of Human Rights must be reviewed".
"All right minded people will be angry and disturbed that a freely given confession, by someone of sound mind, taped and witnessed, can no longer be used as evidence in a court of law," he said.
"This mess needs to be sorted as soon as possible and Scottish Conservatives stand ready to work with the rest of parliament to limit the damage."