BRUSSELS (AP) -- The European Union's top court on Tuesday scrapped key legislation allowing the indiscriminate collection of Internet and phone communication data for law-enforcement purposes.

The European Court of Justice ruled that the data retention directive offers too few safeguards to protect people from authorities' snooping and created an impression that "private lives are the subject of constant surveillance."

EU governments will now scramble to draft new legislation on data scrutiny to help prevent serious crimes such as terrorism while narrowing the law's scope to conform with the judges' verdict.

"Data retention for the purpose of investigating serious crimes is necessary and that remains the case," German Interior Minister Thomas de Maiziere told reporters after the ruling, urging quick agreement on more narrowly defined new legislation.

Germany, the most populous of the EU's 28 nations, did not implement the directive amid court challenges and domestic political differences.

The 2006 legislation required telecommunication firms to store phone calls or online communication records for at least six months and up to two years. The data typically reveals who was involved in the communication, where it originated, when and how often — but not its content.

Still, the Luxembourg-based court ruled the legislation provided "very precise information on private lives," including daily habits and social relationships that represented a "particularly serious interference with fundamental rights."

Green European Parliament lawmaker Jan Philipp Albrecht called the ruling "a major victory for civil rights in Europe" and insisted the data collection also "totally failed to lead to any noticeable improvement in law enforcement."

The EU court said also the legislation's failure to ensure the storage of communication data in the EU alone also represented a potential breach of privacy laws.

___

Associated Press writer Geir Moulson in Berlin contributed to this report.

___

Follow Juergen Baetz on Twitter at http://www.twitter.com/jbaetz