Britain's intelligence services will enter a new era from Tuesday as controversial new spying laws take effect.
The landmark Investigatory Powers Bill - described by former prime minister David Cameron as one of the most important pieces of legislation of this parliament - is due to be given royal assent.
First unveiled a year ago, the legislation aims to bring surveillance tactics used by police and spy agencies in the digital age under one legal umbrella.
Powers covered by the new regime include:
:: Internet connection records: Communications firms will be required to store data relating to what sites a device connects to - but not a user's full browsing history or the content of a communication - for up to a year.
:: Bulk powers: The tactics used by MI5, MI6 and GCHQ to collect vast troves of data.
:: Equipment Interference: The official phrase used for operations involving hacking into suspects' smartphones and PCs, which are seen as increasingly important as advanced encryption makes monitoring targets more difficult.
The Bill has attracted intense scrutiny, with a string of parliamentary reports calling for revisions while it has come under attack repeatedly from civil liberties groups.
But ministers say it will ensure law enforcement and the security and intelligence agencies have the powers they need in a digital age to disrupt terrorist attacks.
The Home Office said the legislation brings together and updates existing powers while radically overhauling how they are authorised and overseen.
It includes the introduction of a "double lock" regime for the most intrusive techniques, so that warrants issued by a Secretary of State will require the approval of a senior judge.
A new Investigatory Powers Commissioner will be created, while those misusing the powers could face sanctions including criminal charges.
Home Secretary Amber Rudd said: "This Government is clear that, at a time of heightened security threat, it is essential our law enforcement, security and intelligence services have the powers they need to keep people safe.
"The internet presents new opportunities for terrorists and we must ensure we have the capabilities to confront this challenge. But it is also right that these powers are subject to strict safeguards and rigorous oversight.
"The Investigatory Powers Act is world-leading legislation that provides unprecedented transparency and substantial privacy protection."
Some of the provisions in the Bill will require extensive testing and will not be in place for some time, the Home Office said.
In the meantime, measures required to replace the Data Retention and Investigatory Powers Act 2014 (DRIPA), which expires on December 31, will take effect.