A US district judge on Friday dismissed the American Civil Liberties Union's lawsuit against the government's top spy agency, ruling that bulk collection of telephony metadata by the NSA is lawful.

In June, the ACLU filed suit to challenge the constitutionality of the National Security Agency's mass collection of phone records, arguing that the practice violates Americans' First and Fourth Amendment rights. The ACLU sought a preliminary injunction to stop the government's phone-surveillance program and to have all of the collected data deleted.

In his ruling Friday in ACLU vs. James R. Clapper, US District Judge William Pauley said that the US government had a pressing need for the surveillance program as a method for detecting and preventing terrorist attacks and that it did not go to unreasonable lengths in that pursuit.

There is no evidence that the Government has used any of the bulk telephony metadata it collected for any purpose other than investigating and disrupting terrorist attacks. While there have been unintentional violation of guidelines, those appear to stem from human error and the incredibly complex computer programs that support this vital tool. And once detected, those violations were self-reported and stopped. The bulk telephony metadata collection program is subject to executive and congressional oversight, as well as continual monitoring by a dedicated group of judges who sit on the Foreign Intelligence Surveillance Court.

"No doubt, the bulk telephony metadata collection program vacuums up information about virtually every telephone call to, from, or within the United States," Pauley said in his conclusion. "That is by design, as it allows the NSA to detect relationships so attenuated and ephemeral they would otherwise escape notice. As the September 11th attacks demonstrate, the cost of missing such a thread can be horrific."

Pauley's ruling also drew a comparison between the NSA's surveillance efforts and US citizens' routine sharing of personal data. "Every day, people voluntarily surrender personal and seemingly-private information to transnational corporations, which exploit that data for profit. Few think twice about it, even though it is far more intrusive than bulk telephony metadata collection."

The ACLU vowed to press on with the case.

"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, ACLU deputy legal director, in a statement. "As another federal judge and the president's own review group concluded last week, the National Security Agency's bulk collection of telephony data constitutes a serious invasion of Americans' privacy. We intend to appeal and look forward to making our case in the Second Circuit."

In that case, Klayman vs. Obama, Judge Richard Leon on December 16 issued preliminary injunctions to halt the NSA's telephony metadata collection and to have the data already collected be destroyed, but stayed the ruling to allow for appeals.

Two days later, a panel that had been convened by the White House to review US government surveillance activities made a number of recommendations, including that the NSA put an end to its bulk collection of Americans' phone records.

Pauley's decision is embedded below.

Update 10:34 a.m. PT:Added more information from the ruling and background material, as well as the statement from the ACLU.