A federal judge in New York ruled Friday that the NSA's vast collection of telephone records is legal – a victory for the Obama administration. NBC's Pete Williams reports.

A federal judge in New York has ruled that the National Security Agency's massive collection of American citizens' telephone records is both legal and useful.

U.S. District Judge William Pauley wrote in his opinion issued Friday that the program "represents the government's counter-punch" to eliminate al-Qaeda's terror network.

Pauley raised the specter of 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.

The ruling dismisses a suit brought by the American Civil Liberties Union against James Clapper, the director of the NSA, and the Justice Department.

The ACLU said Friday that they plan to appeal their case to the Second Circuit in Manhattan.

“We are extremely disappointed with this decision, which misinterprets the relevant statutes, understates the privacy implications of the government’s surveillance and misapplies a narrow and outdated precedent to read away core constitutional protections,” Jameel Jaffer, ACLU deputy legal director, said in a statement.

But the Justice Department and political supporters of the program praised Pauley’s decision.

"We are pleased the court found the NSA's bulk telephony metadata collection program to be lawful," Justice Department spokesman Peter Carr said.

Rep. Peter King, R-N.Y., a member of the House Homeland Security Committee, called Pauley’s decision a “victory for the patriotic men and women of the NSA.” He said in a statement that he hopes the ruling will lessen the “adulation” for NSA whistleblower Edward Snowden, who remains a fugitive from the U.S. in Moscow.

Earlier this month, Snowden had spoken out in favor of a ruling on Dec. 16 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 surveillance program.

Pauley’s decision appears to conflict with Leon’s, which said the program likely violates the U.S. Constitution's ban on unreasonable search.

Leon said that the government was acting in an “understandable zeal to protect our homeland,” and acknowledged that there were national security interests and new constitutional issues in play.

He batted away the government’s argument that removing certain people from the NSA database would degrade the program.

"I am not convinced at this point in the litigation that the NSA’s database has ever truly served the purpose of rapidly identifying terrorists in time-sensitive investigations," he wrote, "and so I am certainly not convinced that the removal of two individuals from the database will ‘degrade’ the program in any meaningful sense.

Snowden had praised the implications of Leon’s decision, saying “a secret program authorized by a secret court was, when exposed to the light of day, found to violate Americans’ rights.”

It's notable that Pauley, who upheld the NSA's practices, was appointed by President Bill Clinton, a Democrat, while Leon, who viewed the snooping policies with more skepticism, was appointed by President George W. Bush, a Republican.

It would be up to the appeals courts, or ultimately the Supreme Court, to reconcile the two decisions.

NBC News' Pete Williams, The Associated Press and Reuters contributed to this report

Related:

Federal judge says NSA program appears to violate Constitution