Gen. Michael Hayden, former director of both NSA and the Central Intelligence Agency, said the metadata made a contribution to weaving the "tapestry of intelligence" and that judges "are not really in a good position to judge the merits of intelligence collection programs."
An Obama administration official said that on 35 occasions in the past, 15 separate judges assigned to the secretive Foreign Intelligence Surveillance court had declared bulk communications of telephone metadata lawful.
Judge Leon has issued headline-making rulings before. In 2011 he blocked cigarette-warning labels that showed graphic images such as a man with a hole in his throat, saying they were unlawful compelled speech, and this year he ruled that the Federal Reserve ignored the intent of Congress in a case about debit card swipe fees.
Greg Nojeim, senior counsel at the Center for Democracy and Technology, a nonprofit group in Washington, said the ruling "means that the NSA bulk collection program is skating on thin constitutional ice."
In defending the data collection, US Justice Department lawyers have relied in part on a 1979 ruling from the US Supreme Court that said people have little privacy interest when it comes to records held by a third party such as a phone company.
Leon wrote that the latest circumstances were different.
"The government, in its understandable zeal to protect our homeland, has crafted a counter terrorism program with respect to telephone metadata that strikes the balance based in large part on a 34-year-old Supreme Court precedent, the relevance of which has been eclipsed by technological advances and a cell phone-centric lifestyle heretofore inconceivable," he wrote.
Greenwald, a former columnist for The Guardian who wrote about the metadata collection program based on documents leaked to him by Snowden, praised the court ruling.
"This is a huge vindication for Edward Snowden and our reporting. Snowden came forward precisely because he knew that the NSA was secretly violating the constitutional rights of his fellow citizens, and a federal court ruled today that this is exactly what has been happening," Greenwald said in an email.
A committee of experts appointed by the Obama Administration to review NSA activities is expected to recommend that the spy agency give up collection of masses of metadata and instead require telephone companies to hold onto it so it can be searched. But intelligence officials and the phone companies themselves are said to oppose such a plan.