Federal judge William Pauley in New York threw out a petition from the American Civil Liberties Union and said the programme was vital in preventing an al Qaeda terror attack on American soil.
Ten days earlier, however, another federal judge in Washington declared that this "almost Orwellian" surveillance is probably unconstitutional, laying the groundwork for a protracted legal fight.
"The question for this court is whether the government's bulk telephony metadata program is lawful. This court finds it is," said the 54-page ruling published in New York on Friday.
Edward Snowden, a former NSA contractor, sent shockwaves around the world this year by revealing the extent of Washington's electronic eavesdropping on millions of private calls.
The Justice Department welcomed Friday's ruling but the American Civil Liberties Union said it would appeal.
Pauley said the programme, since it is protected by judicial, executive and congressional oversight, does not violate the US Constitution's ban on unreasonable searches and seizures.
"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," he wrote.
The judge sided with US spy chiefs who say that by connecting the dots between archived calls and terrorist suspects, US officials can keep the country safe.
The NSA hoovers up information about virtually every telephone call to, from and within the United States, and says it is the only way to discern patterns left behind by foreign terror groups.
The judge quoted the 2004 report by the 9/11 Commission -- the panel which investigated the 2001 al Qaeda attack on the United States - as saying it was a false choice between liberty and security, as "nothing is more apt to imperil civil liberties than the success of a terrorist attack on American soil."
"As the September 11th attacks demonstrate, the cost of missing such a thread can be horrific. Technology allowed al Qaeda to operate decentralised and plot international terrorist attacks remotely," he wrote.
"The bulk telephony metadata collection program represents the government's counter-punch: connecting fragmented and fleeting communications to reconstruct and eliminate al Qaeda's terror network."
The judge quoted examples in which NSA phone monitoring in 2009 exposed an al Qaeda plot to bomb the New York subway, and cite a plot by convicted terrorist David Headley to bomb a Danish newspaper office.
"Unintentional violations of guidelines," Pauley said, appeared to have stemmed from "human error" and "incredibly complex computer programs" and had been rectified where discovered.
The victorious Justice Department said it was "pleased" with the verdict but ACLU deputy legal director Jameel Jaffer said the organisation was "extremely disappointed".
"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," he said.
Last week, a White House-picked panel recommended that President Barack Obama should curb the NSA's secretive powers.
It submitted a 300-page report with 46 recommendations on how to install safeguards and limit the scope of the NSA programme.
It puts Obama in the tricky spot between those demanding change and the US intelligence community, but the administration is not expected to significantly curtail the mission.
Snowden, a fugitive from US justice granted temporary asylum in Russia, issued a staunch defense of individual privacy in a speech broadcast on Brititsh television on Christmas Day.
COMMENTS
Comments are moderated and generally will be posted if they are on-topic and not abusive.
For more information, please see our Comments FAQ