U.S. District Judge William Pauley said in a written opinion that the program lets the government connect fragmented and fleeting communications and "represents the government's counter-punch" to the al-Qaida's terror network's use of technology to operate decentralized and plot international terrorist attacks remotely.
"This blunt tool only works because it collects everything," Pauley said. "The collection is broad, but the scope of counterterrorism investigations is unprecedented."
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, D.C. 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 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: "As the Sept. 11 attacks demonstrate, the cost of missing such a threat can be horrific."
Pauley said the attacks "revealed, in the starkest terms, just how dangerous and interconnected the world is. While Americans depended on technology for the conveniences of modernity, al-Qaida plotted in a seventh-century milieu to use that technology against us. It was a bold jujitsu. And it succeeded because conventional intelligence gathering could not detect diffuse filaments connecting al-Qaida."
The judge said the NSA intercepted seven calls made by one of the Sept. 11 hijackers in San Diego prior to the attacks, but mistakenly concluded that he was overseas because it lacked the kind of information it can now collect.
Still, Pauley said 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.
A week ago, President Barack Obama said there may be ways of changing the program so that is has sufficient oversight and transparency.
In ruling, Pauley cited the emergency of the program after 20 hijackers took over four planes in the 2001 attacks, flying two into the twin towers of the World Trade Center, one into the Pentagon and a fourth into a Pennsylvania field as passengers tried to take back the aircraft.
"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 dismissed a lawsuit brought by the American Civil Liberties Union, which promised to appeal to the 2nd U.S. Circuit Court of Appeals in Manhattan.
"We're obviously very disappointed," said Brett Max Kaufman, an attorney with the ACLU's National Security Project. "This mass call tracking program constitutes a serious threat to Americans' privacy and we think Judge Pauley is wrong in concluding otherwise."
Justice Department spokesman Peter Carr said: "We are pleased the court found the NSA's bulk telephony metadata collection program to be lawful."
In arguments before Pauley last month, an ACLU lawyer 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.