A US federal judge has ruled that mass government surveillance of the phone network is legal, a week after another court said the opposite.

New York District Judge William Pauley described the snooping as a "counter-punch" against al-Qaeda.

He said the National Security Agency (NSA) programme might even have prevented the 9/11 attacks.

Last week a Washington DC federal judge ruled the surveillance was "likely unconstitutional" and "Orwellian".

But in Friday's decision, Judge Pauley, of the US District Court for the Southern District of New York, said "the balance of equities and the public interest tilt firmly in favour of the Government's position".

'Extremely disappointed'

In his 53-page ruling, he concluded: "The right to be free from searches and seizures is fundamental, but not absolute."

How intelligence is gathered

He also noted: "Every day, people voluntarily surrender personal and seemingly-private information to trans-national corporations, which exploit that data for profit.

"Few think twice about it, even though it is far more intrusive than bulk telephony metadata collection.

"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."

Judge Pauley dismissed a lawsuit brought by the American Civil Liberties Union (ACLU), which told the BBC it would appeal.

"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 the civil rights organisation's deputy legal director, Jameel Jaffer.

The Obama administration, which has been on the defensive over the NSA revelations, welcomed the ruling.

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

'Arbitrary invasion'

Friday's ruling contradicts that on 16 December by Washington DC federal Judge Richard Leon, who said the NSA's surveillance was "indiscriminate" and an "arbitrary invasion".

His 68-page decision backed a conservative activist's legal challenge on the merits of the Fourth Amendment, the clause in the US constitution barring unreasonable search and seizure by the government.

Judge Leon suspended his ruling pending an appeal by the justice department, enabling the programme to continue for now.

The NSA's snooping was leaked in June by Edward Snowden, a former contractor for the agency. He fled to Russia, which granted him temporary asylum.

Under the programme, America's electronic surveillance agency orders Verizon - one of the largest phone companies in the US - to hand over its metadata.

This includes telephone numbers, times and dates of calls, calling card numbers and the serial numbers of phones, from millions of calls Verizon processes in which at least one party is in the US.

The disclosures about the NSA's tracking of the communications by ordinary citizens as well as world leaders, such as German Chancellor Angela Merkel and Brazilian President Dilma Rousseff, have dismayed civil rights activists and diplomats.

In his end-of-year news conference, President Barack Obama hinted at a possible review of such snooping.

In light of "disclosures that have taken place", there might be "another way of skinning the cat", he said earlier this week.

Mr Obama is expected to announce next month whether he will act on a White House-appointed panel's advice to rein in the NSA.

Among the task force's sweeping recommendations were that the spy agency should no longer store the data.

Media playback is unsupported on your device

Media captionLawyer David Rivkin and Glenn Greenwald, the former Guardian columnist, put their arguments forward