The House of Lords inflicted a series of defeats on the government over the Covert Human Intelligence Sources (Criminal Conduct) Bill.
It would allow public authorities, ranging from police and MI5 to HMRC and the Food Standards Agency, to authorise agents and informants to commit crimes while undercover.
The proposed authorisations would not only be issued in the interests of national security or preventing and detecting crime, but also preventing “disorder” and in the “interests of the economic wellbeing of the United Kingdom”.
In October, MPs voted by 317 votes to 256 against an amendment to limit the kind of crimes that could be authorised.
But on Wednesday, the House of Lords approved the same curbs by a narrow majority of 299 votes to 284.
The cross-party amendment, brought by Lord Dubs, Baroness Massey, Lord Rosser and Lord Paddick, said the new criminal conduct authorisations may not include actions that intentionally cause death or grievous bodily harm, pervert the course of justice, include rape and sexual offences or torture.
Lord Paddick said: “We do need legislation to govern the tasking of police informants to commit crime, but this bill goes beyond what is reasonable.
“The Liberal Democrats have managed to add important safeguards to the bill, but the sheer number of fundamental issues that have been raised from all sides should force the government to stop and think again.”
Dan Dolan, of the Reprieve legal charity, said allies including the US, Australia and Canada had inserted “common sense limits” to similar laws.
“MPs should follow their lead when the bill heads back to the Commons,” he added.
The government suffered a further setback a short time later as peers backed strict curbs and safeguards on the use of children and vulnerable people as undercover agents.
Baroness Kidron’s amendment would only permit their involvement in crime in exceptional “circumstances” and with additional protections.
“In every other interaction with the criminal justice system we try to remove children from criminal activity, to take them away from harm and towards safety, but before us is legislation which formalises our ability to do the opposite,” she said. “If, and that must be a big if, we make this extraordinary demand of a child then we must set a very high bar for the circumstances in which that happens.”
Peers also backed a cross-party move to ensure victims that injured as a result of authorised crimes are not barred from claiming compensation.
A further amendment, passed by 282 to 259 votes, raises the test for authorising criminal conduct from “believing” to “reasonably believing” that it is necessary and proportionate to do so.
Responding for the government, Lady Williams said any authorisation not compliant with human rights legislation would be unlawful, and that criminal gangs could create initiation tests if given a “checklist” of banned crimes.
Peter Francis speaks about Stephen Lawrence undercover operation
She told peers: “We are being led by the advice and expertise of operational partners. The decisions that we have made throughout this bill and particularly on this issue are based entirely on the reality that our operational partners experience in the field.”
The amended CHIS Bill will be voted on by the House of Lords before going back to the House of Commons.
James Brokenshire, the security minister, previously told MPs that the bill would make authorised crimes “lawful for all purposes and no crime will have been committed”.
But he denied that it was a licence to “commit any and all crimes” because of human rights laws and codes of practice.
MPs have complained that time to debate the law had been severely limited, amid accusations that the government was rushing the bill through ahead of potentially damaging findings in the ongoing Undercover Policing Inquiry.
Officials have argued that the Human Rights Act must be considered in authorisations and would prevent the most grievous crimes, but several politicians have questioned that assurance and pointed out past injustices.
The bill was drawn up after MI5 narrowly won an Investigatory Powers Tribunal (IPT) ruling over the lawfulness of agents’ crimes, and a separate challenge over the use of children as informants and spies.