This undated handout photo provided by the U.S. District Court for the District of Columbia shows Richard Leon, the judge who declared that the National Security Agency's bulk collection of millions of Americans' telephone records is likely unconstitutional, has a long record of taking on executive branch actions. (AP Photo/U.S. District Court for the District of Columbia)

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.

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.

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.

Pauley dismissed a lawsuit brought by the American Civil Liberties Union. The ACLU did not immediately respond to a message for comment.

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. A government lawyer had countered that counterterrorism investigators wouldn't find most personal information useful.

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.

___

Associated Press writer Mark Sherman contributed to this report.

Copyright 2013 The Associated Press. All rights reserved. This material may not be published, broadcast, rewritten or redistributed.

*We welcome your comments on the stories and issues of the day and seek to provide a forum for the community to voice opinions. All comments are subject to moderator approval before being made visible on the website but are not edited. The use of profanity, obscene and vulgar language, hate speech, and racial slurs is strictly prohibited. Advertisements, promotions, spam, and links to outside websites will also be rejected. Please read our terms of service for full guides