A US judge has ordered the FBI to stop its "pervasive" use of National Security letters to secretly snoop on phone and email records, ruling Friday that the heavily used tactic was unconstitutional.

The order issued by US District Court Judge Susan Illston in San Francisco came as a surprising blow to a measure heavily used by the administration of President Barack Obama in the name of battling terrorism.

The Patriot Act passed after the devastating September 11 attacks gave the Federal Bureau of Investigation strong authority to order that people's telecom records be handed over, without such requests having to be disclosed.

But in her ruling, Illston said evidence indicated that tens of thousands of NSLs are sent out every year, and that 97 percent of them are fettered with the provision that recipients never mention the requests.

"This pervasive use of nondisclosure orders, coupled with the government's failure to demonstrate that a blanket prohibition on recipients' ability to disclose the mere fact of receipt of an NSL is necessary to serve the compelling need of national security, creates too large a danger that speech is being unnecessarily restricted," Illston said in her written decision.

Illston set her ban on NSLs to take effect in 90 days to allow US lawyers to appeal the decision given "the significant constitutional and national security issues at stake."

The judge's ruling came in a lawsuit filed in 2011 by Internet rights law group Electronic Frontier Foundation on behalf of an unnamed telecom company.

"We are very pleased that the court recognized the fatal constitutional shortcomings of the NSL statute," said EFF Senior Staff Attorney Matt Zimmerman.

"The government's gags have truncated the public debate on these controversial surveillance tools."

It was the potential for gag orders accompanying NSLs to violate the First Amendment right of free speech that prompted the ruling, according to Zimmerman.