The Scottish government today lost an appeal to the UK supreme court in a case over human rights that could undermine the convictions of criminals questioned without a lawyer.

A ruling found such questioning was aimed at making it more likely that suspects in Scotland might "incriminate" themselves while being quizzed by police.

The defeat for Scottish ministers – which had been feared for months – has prompted concerns that it could lead to widespread appeals and some criminals walking free from jail.

The Scottish justice minister, Kenny MacAskill, said that in response, with Holyrood's support, he would be making "swift legislative changes to protect the victims of crime and safeguard communities".

Today's supreme court judgment states: "The ECHR [European Convention on Human Rights] requires that a person who has been detained by the police has the right to have access to a lawyer prior to being interviewed."

The changes planned by MacAskill will mean introducing a right of access to legal advice before being questioned, extending the period during which a person may be detained under the Criminal Procedure (Scotland) Act 1995, powers to adjust legal aid eligibility rules and measures to ensure "certainty and finality" in concluded cases.

He said he would be introducing this emergency legislation later today and hoped to have it passed by Friday.

Today's ruling in the case of Peter Cadder, who was convicted at Glasgow sheriff court of two assaults and breach of the peace on interview evidence, is retrospective.

This had prompted fears it could lead to similar appeals in other cases in which convictions have been secured under similar circumstances.

The judgment, though, found that cases which have already been dealt with by courts and not appealed against within the usual deadlines must not now be reviewed as a "miscarriage of justice".

But it added: "The Scottish Criminal Cases Review Commission must make up its own mind, if it is asked to do so, as to whether it would be in the public interest for those cases to be referred to the high court.

"It will be for the appeal court to decide what course it ought to take if a reference were to be made to it on those grounds by the commission."

New interim guidance was issued to police in Scotland earlier this year, warning that suspects should now be given access to legal representation when they are interviewed and that this would become permanent. Previously, suspects could be questioned for six hours without a lawyer being present.

This is different a situation different to that in England and Wales, where an accused person has a legal right to a lawyer.

Among the cases that may be affected by today's ruling is that of Luke Mitchell, who was 14 when he was questioned without a lawyer by police investigating the murder of his girlfriend, Jodi Jones. His case is already being investigated by the Criminal Cases Review Commission.

MacAskill said today's decision overturned decades of criminal procedure in Scotland, "a proud, distinctive, justice system, developed over centuries, and predicated on fairness with many rigorous protections for accused persons".

The justice minister 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. But we cannot ignore the supreme court's decision.

"And while it necessitates changes to Scotland's justice system, these are changes that have been anticipated and planned for. For over a year, the Scottish government, Crown Office, Scottish Legal Aid Board (SLAB), ACPOS [Association of Chief Police Officers in Scotland] and the Scottish court service have been preparing contingency plans to deal with all possible eventualities arising from this case.

He said he had also asked Lord Carloway, a senior high court judge, to lead a review of Scottish criminal law and practice in the aftermath of the Cadder decision and report back within months.

"Our distinctive justice system is one which protects accused persons," MacAskill said. "However, human rights also extend to victims and to all of the people of Scotland, and the Scottish government and justice partners will continue to fight to ensure that the rights of the victims and indeed wider society remain at the forefront of the Scottish justice system."

Elish Angiolini QC, Scotland's lord advocate, said prosecutors would have to "immediately adapt our working practices to this new legal landscape".

But she added: "I note that the court has stated that its decision does not apply to cases that have been finally determined. This very significantly limits the number of cases potentially affected by this judgment."