NEW YORK (AP) -- A federal judge on Friday found that the National Security Agency's bulk collection of millions of Americans' telephone records is legal and a valuable part of the nation's arsenal to counter the threat of terrorism and "only works because it collects everything."
U.S. District Judge William Pauley said in a written opinion that the program "represents the government's counter-punch" to eliminate al-Qaida's terror network by connecting fragmented and fleeting communications.
"This blunt tool only works because it collects everything," Pauley said. "The collection is broad, but the scope of counterterrorism investigations is unprecedented."
He said the mass collection of phone data "significantly increases the NSA's capability to detect the faintest patterns left behind by individuals affiliated with foreign terrorist organizations. Armed with all the metadata, NSA can draw connections it might otherwise never be able to find."
He added that such a program, if unchecked, "imperils the civil liberties of every citizen" and he noted the lively debate about the subject across the nation, in Congress and at the White House.
"The question for this court is whether the government's bulk telephony metadata program is lawful. This court finds it is. But the question of whether that program should be conducted is for the other two coordinate branches of government to decide," he said.
In ruling, the judge noted the Sept. 11 terrorist attacks and how the phone data-collection system could have helped investigators connect the dots before the attacks occurred.
"The government learned from its mistake and adapted to confront a new enemy: a terror network capable of orchestrating attacks across the world. It launched a number of counter-measures, including a bulk telephony metadata collection program — a wide net that could find and isolate gossamer contacts among suspected terrorists in an ocean of seemingly disconnected data," he said.
Pauley's decision contrasts with a ruling earlier this month by U.S. District Court Judge Richard Leon, who granted a preliminary injunction against the collecting of phone records of two men who had challenged the program. The Washington jurist said the program likely violates the U.S. Constitution's ban on unreasonable search. The judge has since stayed the effect of his ruling, pending a government appeal.
Pauley dismissed a lawsuit brought by the American Civil Liberties Union. The ACLU did not immediately respond to a message for comment.
"We are pleased with the decision," Justice Department spokesman Peter Carr said.
In arguments before Pauley last month, an ACLU lawyer had argued that the government's interpretation of its authority under the Patriot Act was so broad that it could justify the mass collection of financial, health and even library records of innocent Americans without their knowledge, including whether they had used a telephone sex hotline, contemplated suicide, been addicted to gambling or drugs or supported political causes. A government lawyer had countered that counterterrorism investigators wouldn't find most personal information useful.
Pauley said there were safeguards in place, including the fact the NSA cannot query the phone database it collects without legal justification and is limited in how much it can learn. He also noted "the government repudiates any notion that it conducts the type of data mining the ACLU warns about in its parade of horribles."
The ACLU sued earlier this year after former NSA analyst Edward Snowden leaked details of the secret programs that critics say violate privacy rights. The NSA-run programs pick up millions of telephone and Internet records that are routed through American networks each day.
Pauley said the fact that the ACLU would never have learned about an order authorizing collection of telephony metadata related to its telephone numbers but for Snowden's disclosures added "another level of absurdity in this case."
"It cannot possibly be that lawbreaking conduct by a government contractor that reveals state secrets — including the means and methods of intelligence gathering — could frustrate Congress's intent. To hold otherwise would spawn mischief," he wrote.
Pauley also rejected the ACLU's argument that the phone data collection program is too broad and contains too much irrelevant information.
"That argument has no traction here. Because without all the data points, the government cannot be certain it connected the pertinent ones," he said. "Here, there is no way for the government to know which particle of telephony metadata will lead to useful counterterrorism information. When that is the case, courts routinely authorize large-scale collections of information, even if most of it will not directly bear on the investigation."
Associated Press writer Mark Sherman in Washington contributed to this report.