A federal judge in New York ruled Friday that the massive collection of domestic telephone data brought to light by former National Security Agency contractor Edward Snowden is lawful, rejecting a challenge to the program by the American Civil Liberties Union.

The decision marked a victory for the government less than two weeks after a District of Columbia federal judge ruled against it, finding that the NSA's program was almost certainly unconstitutional. If the split in rulings continues through the appeals process, it is likely the Supreme Court will have to decide the issue.

In a 53-page opinion, U.S. District Judge William Pauley said Friday that the program, which collects virtually all Americans' phone records, represents the U.S. government's "counterpunch" to eliminate the al-Qaida terrorist network and does not violate the Fourth Amendment, which prohibits unreasonable search and seizure.

Pauley endorsed the assertion made by government officials that if the United States had the phone data collection program before 2001, they might have had a better chance at preventing the Sept. 11 attacks.

"The government learned from its mistake and adapted to confront a new enemy: a terror network capable of orchestrating attacks across the world," Pauley wrote. "It launched a number of countermeasures, 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 added: "This blunt tool only works because it collects everything."

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

In a statement, the ACLU said it intended to appeal the case to the U.S. Court of Appeals for the 2nd Circuit.

"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," said Jameel Jaffer, an ACLU deputy legal director.

The ACLU filed its lawsuit on June 11, just days after the telephone data collection program was revealed by Britain's Guardian newspaper, based on documents obtained from Snowden.

In granting the government's motion to dismiss the case, ACLU v. Clapper, Pauley said that the sweeping collection of phone records is lawful under Section 215 of the Patriot Act and under the Fourth Amendment. But he added that the issue of whether the program should be conducted is "for the other two coordinate branches of Government to decide." The ACLU brought the suit against James Clapper, the director of national intelligence.

The NSA program collects records of the numbers that Americans call and the duration of those calls, but not content. Civil liberties advocates have argued that the collection and storage of that data represent a violation of Americans' right to privacy.