Undercover informants working for the police and MI5 are going to be explicitly permitted for the first time under British law to commit crimes.
The unprecedented legislation to authorise and oversee crimes comes after years of unclear rules over when these agents can break the law.
The law will not specify exactly which crimes can be committed.
And critics are urging MPs to amend the proposed law to rule out murder and serious violence.
The highly unusual decision to create a law that sanctions crime comes after a legal battle to force MI5 and the government to reveal secret rules governing when an informant can break the law.
Informants - also known as agents - are recruited to gather intelligence on targets, including terrorist organisations, major drugs gangs and child abuse networks.
These agents are often already involved in the networks being targeted and need to maintain a cover in order to gather critical evidence for investigators.
However, a major court ruling last year found that while MI5 had an "implied" power to authorise crimes - it did not mean anyone involved was immune from prosecution.
That judgement, only narrowly in the government's favour, prompted the decision to create the new law.
Under the legislation going before Parliament on Thursday, MI5, the police, the National Crime Agency and other agencies that use informants or undercover agents will be able to explicitly authorise them to commit a specific crime as part of an operation.
The law will require MI5 officers and others to show the crime is "necessary and proportionate".
Security officials will not say which crimes they will consider authorising because that could lead to terrorists and other serious criminals working out who is working undercover.
But the legislation stresses agencies must not breach the Human Rights Act, which requires the government to protect life.
While the security service's watchdog, a senior judge, will report on how the power is used, there will be no role for the Crown Prosecution Service in reviewing the crimes.
27 plots foiled
Ken McCallum, the new Director General of MI5, said agents working deep undercover had played a critical role in stopping many of the 27 terror plots that have been uncovered in the last three years.
"Without the contribution of human agents, be in no doubt, many of these attacks would not have been prevented," he said.
And Security Minister James Brokenshire said the new law had in-built guarantees.
"This is a critical capability and is subject to robust, independent oversight. It is important that those with a responsibility to protect the public can continue this work, knowing that they are on a sound legal footing."
But Maya Foa, director of Reprieve, a legal and human rights campaign group that challenged the secrecy around the rules, said: "We are seriously concerned that the bill fails to expressly prohibit MI5 and other agencies from authorising crimes like torture, murder and sexual violence.
"Our intelligence agencies do a vital job in keeping this country safe, but there must be common sense limits on their agents' activities, and we hope MPs will ensure these limits are written into the legislation".
Which agencies will be able to authorise secret crimes?
- MI5 and other intelligence bodies
- Police forces and the National Crime agency
- Immigration and Border Officers
- HM Revenue and Customs, Serious Fraud Office
- UK military forces
- Ministry of Justice (investigations in prisons)
- Competition and Markets Authority, Environment Agency, Financial Conduct Authority, Food Standards Agency, Gambling Commission and Medicines and Healthcare Regulation Authority