The American Civil Liberties Union called the ruling a "landmark victory" against the Justice Department's post-Sept. 11 law enforcement powers.
"Today's ruling is a wholesale refutation of excessive government secrecy and unchecked executive power," said ACLU attorney Jameel Jaffer.
Federal Judge Victor Marrero struck down a provision of the Patriot Act that authorizes the FBI to force Internet service providers and phone companies to turn over certain customer records. The companies are then barred from ever disclosing the search took place.
In his ruling, the judge called national security of "paramount value" and said the government "must be empowered to respond promptly and effectively" to threats. But he called personal security equal in importance and "especially prized in our system of justice."
Marrero said his ruling blocks the government from issuing the requests or from enforcing the non-disclosure provision "in this or any other case." But the ruling will not immediately take effect to allow for an appeal.
Megan L. Gaffney, a spokeswoman for the federal prosecutor's office in Manhattan, said the government was reviewing the decision and had no immediate comment.
The judge said the law violates the Fourth Amendment because it bars or deters any judicial challenge to the government searches, and violates the First Amendment because its permanent ban on disclosure is a prior restraint on speech.
He noted that the Supreme Court recently said that a "state of war is not a blank check for the president when it comes to the rights of the nation's citizens."
"Sometimes a right, once extinguished, may be gone for good," Marrero wrote.
Marrero issued his decision in favor of an Internet access firm identified in his 120-page ruling as "John Doe." He had agreed to keep the firm's identity secret to protect the FBI probe that led to the search request.
Jaffer, the ACLU lawyer, said the government had turned over as part of the lawsuit a six-page document showing it had obtained Internet or telephone records dozens and possibly hundreds of times.
The government was authorized to pursue communications records as part of a 1986 law. Its powers were enhanced by legislation passed after the passage of the Patriot Act in 2001.
In a footnote to his ruling, Marrero cited words he had written two years ago in another case to warn that courts must apply "particular vigilance to safeguard against excess committed in the name of expediency."
"The Sept. 11 cases will challenge the judiciary to do Sept. 11 justice, to rise to the moment with wisdom equal to the task, its judgments worthy of the large dimensions that define the best Sept. 11 brought out of the rest of American society."