Said Dean Boyd, a Justice Department spokesman: "We are reviewing the decision and considering our options at this time."
National security letters -- first authorized in 1986 -- have become one of the FBI's bedrock investigative tools since Congress made them easier to issue as part of the original USA Patriot Act, enacted weeks after the attacks on New York and the Pentagon.
But they also have been a source of criticism, even within the Justice Department.
In a report released in March, the department's inspector general found that many letters had been issued in violation of Justice Department regulations. The watchdog office also found that the FBI's record-keeping system for the letters was in such disarray that reports to Congress understated by thousands the number of letters the bureau was issuing.
Civil-liberties groups praised Thursday's ruling.
The American Civil Liberties Union, which filed the challenge, had argued that legal problems with the statute led to the often-troubled process of how issuing the letters worked in practice.
"One of the arguments we made to Judge Marrero was that the kinds of constitutional deficiencies that the court found in the statute are the kinds that led to the abuses that the [inspector general] documented," said Jameel Jaffer, a lawyer who heads up the ACLU national-security law program. "The FBI can't be invested with the authority to determine by itself, without meaningful judicial oversight, which [national security letter] recipients should be allowed to speak, and which ones should be silenced."
Thursday's ruling follows changes that Congress made last year to address a 2004 ruling by Marrero that found other problems with the letters.
The original Patriot Act prohibited phone companies and Internet providers in all cases from revealing the existence of a national security letter; Marrero found that patently unconstitutional.
Congress -- in legislation reauthorizing the Patriot Act last year -- changed the law to require that the FBI decide in each case whether disclosure would result in a danger to national security. The law was also changed to give letter recipients a limited right to challenge the gag orders in court, but required courts to accept as "conclusive" testimony of FBI officials who found secrecy was needed.
Marrero on Thursday said those standards were "overly deferential" to the government, and forestalled "meaningful judicial review."