MSPs have refused consent for the UK Government's controversial "spy cops" legislation, which would allow undercover agents to break the law.
Justice Secretary Humza Yousaf said insufficient safeguards have been put in place despite "limited" improvements.
The move means Scotland will be removed from the provisions of the Covert Human Intelligence Sources (Criminal Conduct) Bill.
Critics said this could jeopardise public safety.
Yousaf acknowledged it could mean Holyrood has to pass emergency legislation in future to "ensure the security of police operations".
The controversial bill would allow undercover agents to commit crimes in the course of their work, creating a new class of permission called a Criminal Conduct Authorisation.
This could be used by a range of bodies including Police Scotland.
CCAs make specific conduct “lawful for all purposes” and protect the person doing it from any liability.
The conduct must be deemed necessary and proportionate, but there is no limit on the offence it could cover, so that criminals could not devise tests to uncover any moles.
Speaking in Holyrood, Scottish Labour MSP Neil Findlay said it would be a "human rights scandal waiting to happen" and an "affront to our democracy".
Scottish Liberal Democrat MSP Liam McArthur said the bill places "no limits on the type of crime that can be authorised, not rape, not torture, not even murder" and includes no requirement for prior judicial approval.
But Scottish Conservative MSP Liam Kerr said the ability to carry out vital covert work "presently lacks statutory foundation".
He said a court case has been brought against the UK Government relating to covert sources, with an appeal judgement due soon.
He added: "It is possible that the court will find that the current system of covert surveillance is unlawful.
"In such an event, the UK would have no basis for undertaking covert surveillance into, for example, terrorism, cyber crime, people trafficking or drugs running.
"The UK bill anticipates this, setting a statutory framework allowing our security services and our police to continue to protect us.
"That bill contains provisions to ensure such practices can continue in Scotland, hence the request for legislative consent today."
Kerr said if Holyrood does not consent, the UK Government will remove Scotland from the bill's provisions.
This means that if the court ruling finds against current practices, they will have to cease in Scotland immediately, he said.
He said Holyrood would then be required to pass emergency legislation in the middle of a pandemic to ensure operations can continue.
Kerr told MSPs: "This is vital legislation which provides a clear and consistent statutory basis for public authorities to keep the public safe.
"Failure to give consent risks leaving Scotland's people exposed.
"That is deeply irresponsible, and I cannot believe that any MSP would vote to countenance such a situation."
Yousaf said the UK Government has not brought forward amendments to the bill that satisfy his concerns.
He said "independent judicial scrutiny" before any activity takes place would go "a long way" towards addressing worries.
However he acknowledged the forthcoming Court of Appeal judgement may require "emergency or expedited legislation" to be passed in Scotland.
He said: "That would, of necessity, be no more than just a sticking plaster to ensure the security of police operations.
"If such a measure is required, it would only be a stopgap to allow a full assessment of the Court of Appeal judgement.
"That assessment will, in turn, inform any subsequent measures that may have to be put in place by this Government or indeed by any future Government post elections."
MSPs voted to refuse consent by 92 votes to 27, with only the Tories backing the Bill.
Scottish Labour's decision to reject it contrasts with the party's policy in Westminster, where UK Labour leader Sir Keir Starmer has told MPs and peers to abstain.
Two Labour frontbenchers resigned last year after voting against the legislation.
Why are you making commenting on The National only available to subscribers?
We know there are thousands of National readers who want to debate, argue and go back and forth in the comments section of our stories. We’ve got the most informed readers in Scotland, asking each other the big questions about the future of our country.
Unfortunately, though, these important debates are being spoiled by a vocal minority of trolls who aren’t really interested in the issues, try to derail the conversations, register under fake names, and post vile abuse.
So that’s why we’ve decided to make the ability to comment only available to our paying subscribers. That way, all the trolls who post abuse on our website will have to pay if they want to join the debate – and risk a permanent ban from the account that they subscribe with.
The conversation will go back to what it should be about – people who care passionately about the issues, but disagree constructively on what we should do about them. Let’s get that debate started!
Callum Baird, Editor of The National
Comments: Our rules
We want our comments to be a lively and valuable part of our community - a place where readers can debate and engage with the most important local issues. The ability to comment on our stories is a privilege, not a right, however, and that privilege may be withdrawn if it is abused or misused.
Please report any comments that break our rules.
Read the rules hereLast Updated:
Report this comment Cancel