British Prime Minister David Cameron unveiled emergency legislation Thursday to compel phone companies and Internet providers to store their customers’ records, arguing that data needed to track down criminals and terrorists could otherwise be deleted.

The British move comes three months after the Court of Justice of the European Union ruled that forcing communications companies to keep records of their customers’ calls and Internet use violated rights to privacy and protection of personal data.

The ruling dealt a blow to security services by invalidating the legal basis under which they have scooped up phone logs and records of e-mail traffic. Cameron said Thursday that without new legislation, law enforcement efforts would be severely compromised because communications companies could start deleting data within weeks, unless they had a business reason to keep it.

“If we don’t do anything, our ability to solve crimes will be radically reduced, and our ability to prevent terrorist attacks will be radically reduced,” Cameron said Thursday at a Downing Street news conference.

Cameron stressed that the new legislation would not expand government powers and would only maintain security services’ existing access to records of whom was contacted and when, rather than the content of any messages. Under a deal reached with the two other main parties — Labor and the Liberal Democrats — the government will institute new safeguards to ensure that the data is not misused, including the appointment of a new Privacy and Civil Liberties Oversight Board.

But civil liberties advocates said Thursday that the legislation does not go nearly far enough in protecting individuals from government surveillance.

“Not only will the proposed legislation breach our right to privacy, it will also set a dangerous precedent where the government simply re-legislates every time it disagrees with a decision” by the European Court of Justice, said Jim Killock, executive director of the Open Rights Group.

Tom Watson, a Labor member of Parliament who frequently advocates for civil liberties, said the use of emergency measures to push the legislation through Parliament prevented a proper debate on a critical issue.

“Regardless of where you stand on the decision of the European Court of Justice, can you honestly say that you want a key decision about how your personal data is stored to be made by a stitch up behind closed doors and clouded in secrecy?” Watson wrote in an Internet post.

With support from the leadership of all three main British parties, the legislation is expected to pass Parliament next week.

The debate over government surveillance of communications has intensified over the past year, following revelations from former U.S. National Security Agency contractor Edward Snowden about the extent of government snooping. But the debate has been far less intense in Britain than it has been in the United States, with comparatively little outrage here over the government’s efforts.

The new legislation will automatically lapse by the end of 2016, meaning that the Parliament elected next year will have to revisit the issue.

In the United States, occasional efforts in Congress to mandate data retention for U.S. companies have gone nowhere because of strong opposition by the businesses, privacy groups and many lawmakers.

The issue was raised again as Congress debates legislation to end an NSA counterterrorism program that gathers billions of Americans’ call records. The current proposal is to supplant it with a regime in which the phone companies retain the data — but for no longer than they ordinarily would, which is generally a minimum of 18 months.

Ellen Nakashima in Washington and Karla Adam in London contributed to this report.