A US court here today ruled that the National Security Agency's controversial telephone surveillance programme was "lawful" and the snooping was a valuable component to eliminate al-Qaeda's terror network.

In a 53-page ruling, New York District Judge William Pauley said the NSA's bulk telephony metadata collection programme is "lawful" and granted the US government's motion to dismiss the complaint filed against it by the American Civil Liberties Union (ACLU).

The Judge said the September 11 terrorist attacks had revealed "just how dangerous and interconnected" the world is, adding that the terror group used technology against the country and succeeded because "conventional intelligence gathering" by the government could not detect "diffuse filaments connecting al-Qaeda."

"The government learnt from its mistake" and launched a number of counter-measures including a bulk telephony metadata collection programme. "This blunt tool only works because it collects everything," Judge Pauley said in the ruling.

"While robust discussions are underway arcoss the nation, in Congress and at the White House, the question for this Court is whether the government's bulk telephony metadata programme is lawful. The Court finds it is. But the question of whether that programme should be conducted is for the other two coordinate branches of Government to decide," the court ruled.

The court dismissed and denied ACLU's motion for a preliminary injuction. The ACLU lawsuit had challenged the legality of the NSA programme after it was disclosed in June.

"The natural tension between protecting the nation and preserving civil liberty is squarely presented by the Government's bulk telephony metadata collection programme," Pauley said.

The judge said he had found no evidence that the government used any of the phone data for any purpose other than investigating and disrupting terrorist attacks.

"No doubt, the bulk telephony metadata collection programme vacuums up information about virtually every telephone call to, from, or within the United States. That is by design, as it allows the NSA to detect relationships so attenuated and ephemeral they would otherwise escape notice" he said.

"As the September 11th attacks demonstrate, the cost of missing such a thread can be horrific," the judge said.

The ruling contrasts with another ruling last week by another federal judge in Washington, who called the same programme "almost Orwellian" and likely unconstitutional.

The ACLU had 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.