NEW YORK — Citing the Sept. 11 attacks, a federal judge ruled Friday that the National Security Agency's bulk collection of millions of Americans' telephone records is legal, a valuable tool in the nation's arsenal to fight terrorism that “only works because it collects everything.” US 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-Qaeda'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 US 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 US 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-Qaeda 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-Qaeda.” 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. Pauley dismissed a lawsuit brought by the American Civil Liberties Union, which promised to appeal to the 2nd US 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 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. — AP