The Scottish Parliament has rushed through a new emergency law, after a landmark legal ruling over the police questioning of suspects.
The UK Supreme Court upheld an appeal by teenager Peter Cadder, whose assault conviction was based on evidence gained before he spoke to his solicitor.
On Tuesday, the judges in London ruled this breached human rights law.
The Criminal Procedure (Detention, Legal Assistance and Appeals) Bill was passed by 97 votes to 18.
Justice Secretary Kenny MacAskill told the Scottish Parliament it was vital to act after concern was raised that almost 3,500 cases could be open to appeal under the Cadder ruling.
Therefore the three scrutiny stages which every bill needs to pass through were cut from several months to one afternoon in order to implement the new law.
MSPs sat late into Wednesday evening to see it through.
The Liberal Democrats claimed the bill was too rushed.
The emergency legislation legally requires police to provide access to a lawyer, while the period of time someone can be detained without charge rises from six to 12 hours, with the possibility of a further increase to 24 hours.
It also deals with increased costs to the state-funded legal aid system - which could rise by several million pounds - as well as tackling concerns over the bringing forward of appeals through the Scottish Criminal Cases Review Commission, which investigates possible miscarriages of justice.
But Liberal Democrat justice spokesman Robert Brown said the bill failed to strike the right balance between the rights of suspects and the public.
In the end, the party, along with the Greens voted against the bill.
He said: "The Liberal Democrats are unpersuaded of the need for emergency legislation and regard the terms of the bill as being unnecessary in part, meaningless in part, with the need for the extension of the detention period unproven at best."
But responding, Mr MacAskill argued: "The scales of justice require we do now recognise the importance of a lawyer being in for interrogation and investigation.
"Equally, we've got to remember the rights of victims for those who police and prosecute our communities to have a fair balance - if we don't have that extension then we undermine that balance."
Labour's Richard Baker said emergency legislation was not a "desirable situation".
He added: "While we are always ready to provide opposition to government measures when that's the right thing to do.
"In this situation we do believe it's the responsible action to accept the cabinet secretary's argument for emergency legislation, and also the broader direction he has decided to take as a result of the judgment."
Tory MSP John Lamont said it was wrong to suggest Tuesday's Supreme Court ruling was the decision of "some foreign court imposing its will on Scottish law".
However he said: "I detected more than a hint of this in the comments by the cabinet secretary for justice during his various media interviews over the last 24 hours."
Green MSP Patrick Harvie said human rights were not an inconvenience to be worked around, but an important principle.
He added: "It's crucial that people have a right to bring a challenge where they feel that human rights violations may have occurred."
Among the cases affected by the Cadder ruling, which is not retrospective but applies to current cases, 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.