The Federal Constitutional Court ruled that random data trawling was legal only when there was a "concrete danger" to security or lives.
Coordinated profiling for potential terrorists was introduced by states across Germany after Sept. 11, when it emerged that three of the suicide pilots had lived and studied undetected in Hamburg.
It allowed authorities to scan for young Muslim men who might fit the profile of terrorist "sleepers" in university and residency records that would normally be off-limits under privacy laws, and compare them with data held by investigators.
The search met with very limited success, with no genuine terrorist suspects uncovered.
The experience shows that "terrorists cannot be caught through data profiling," said Ingo Wolf, interior minister of North Rhine-Westphalia state, the home region of the plaintiff, the AP reports.
"There are better-suited methods to head off effectively and legally the dangers that arise from Islamic terrorism," Wolf said. He said he did not expect Tuesday's ruling to affect security.
North Rhine-Westphalia, Germany's most populous state, scanned data on 5 million men aged 18 to 40 after the Sept. 11 attacks, although there was no firm evidence that any attack was planned in the region.
The Moroccan student, Najim Azahaf, had appealed unsuccessfully to lower courts against the procedure.
Subscribe to Pravda.Ru Telegram channel, Facebook, RSS!