A federal judge in Washington ruled on Monday that the bulk collection of Americans’ telephone records by the National Security Agency is likely to violate the US constitution, in the most significant legal setback for the agency since the publication of the first surveillance disclosures by the whistleblower Edward Snowden.

Judge Richard Leon declared that the mass collection of metadata probably violates the fourth amendment, which prohibits unreasonable searches and seizures, and was "almost Orwellian" in its scope. In a judgment replete with literary swipes against the NSA, he said James Madison, the architect of the US constitution, would be "aghast" at the scope of the agency’s collection of Americans' communications data.

The ruling, by the US district court for the District of Columbia, is a blow to the Obama administration, and sets up a legal battle that will drag on for months, almost certainly destined to end up in the supreme court. It was welcomed by campaigners pressing to rein in the NSA, and by Snowden, who issued a rare public statement saying it had vindicated his disclosures. It is also likely to influence other legal challenges to the NSA, currently working their way through federal courts.

The case was brought by Larry Klayman, a conservative lawyer, and Charles Strange, father of a cryptologist killed in Afghanistan when his helicopter was shot down in 2011. His son worked for the NSA and carried out support work for Navy Seal Team Six, the elite force that killed Osama bin Laden.

In Monday’s ruling, the judge concluded that the pair's constitutional challenge was likely to be successful. In what was the only comfort to the NSA in a stinging judgment, Leon put the ruling on hold, pending an appeal by the government.

Leon expressed doubt about the central rationale for the program cited by the NSA: that it is necessary for preventing terrorist attacks. “The government does not cite a single case in which analysis of the NSA’s bulk metadata collection actually stopped an imminent terrorist attack,” he wrote.

“Given the limited record before me at this point in the litigation – most notably, the utter lack of evidence that a terrorist attack has ever been prevented because searching the NSA database was faster than other investigative tactics – I have serious doubts about the efficacy of the metadata collection program as a means of conducting time-sensitive investigations in cases involving imminent threats of terrorism.”

Leon’s opinion contained stern and repeated warnings that he was inclined to rule that the metadata collection performed by the NSA – and defended vigorously by the NSA director Keith Alexander on CBS on Sunday night – was unconstitutional.

“Plaintiffs have a substantial likelihood of showing that their privacy interests outweigh the government’s interest in collecting and analysing bulk telephony metadata and therefore the NSA’s bulk collection program is indeed an unreasonable search under the fourth amendment,” he wrote.

Leon said that the mass collection of phone metadata, revealed by the Guardian in June, was "indiscriminate" and "arbitrary" in its scope. "The almost-Orwellian technology that enables the government to store and analyze the phone metadata of every telephone user in the United States is unlike anything that could have been conceived in 1979," he wrote, referring to the year in which the US supreme court ruled on a fourth amendment case upon which the NSA now relies to justify the bulk records program.

Snowden welcomes ruling

In a statement, Snowden said the ruling justified his disclosures. “I acted on my belief that the NSA's mass surveillance programs would not withstand a constitutional challenge, and that the American public deserved a chance to see these issues determined by open courts," he said in comments released through Glenn Greenwald, the former Guardian journalist who received leaked documents from Snowden.

"Today, a secret program authorised by a secret court was, when exposed to the light of day, found to violate Americans’ rights. It is the first of many.”

Senator Mark Udall, a leading critic of the dragnet collection, welcomed the judgment. "The ruling underscores what I have argued for years: [that] the bulk collection of Americans' phone records conflicts with Americans' privacy rights under the US constitution and has failed to make us safer," said Udall, a Democrat.

Jameel Jaffer, the deputy legal director of the ACLU, praised what he called Leon's "thoughtful" ruling: “This is a strongly worded and carefully reasoned decision that ultimately concludes, absolutely correctly, that the NSA’s call-tracking program can’t be squared with the constitution."

At the White House, spokesman Jay Carney said he had no comment on the on the case, saying he had not heard of the decision when the press briefing started and referred reporters to the Justice Department for reaction.

“We’ve seen the opinion and are studying it. We believe the program is constitutional as previous judges have found. We have no further comment at this time," said Justice Department spokesman Andrew Ames.

News of the ruling came as the White House revealed that its review into NSA activities has made more than 40 separate recommendations in a report received by Barack Obama on Friday. Carney said the president would be reviewing the group's conclusions before making their findings public. “Over the next several weeks we will be reviewing the review group's report and its more than 40 recommendations as we consider the path forward, including sorting through which recommendations we will implement and which might require further study and which will choose not to pursue,” Carney said.

“We expect the overall internal review to be completed in January. After that, the president will deliver remarks to outline the outcome of our work and at that time we will make public the review group's full report and other conclusions of our work.”

The White House also poured cold water on suggestions by an NSA official that whistleblower Edward Snowden could be offered an amnesty by the US in exchange for returning documents. “Our position has not changed on that matter – at all,” said Carney. “Mr Snowden has been accused of leaking classified information and he faces felony charges in the US. He should be returned to the United States as soon as possible, where he will be accorded full due process.”

Asked about the NSA official's suggestion, the White House added: “He was expressing his personal opinion; these decisions are made by the Department of Justice. There has been no change in our position.”

In his ruling, Judge Leon expressly rejected the government’s claim that the 1979 supreme court case, Smith v Maryland, which the NSA and the Obama administration often cite to argue that there is no reasonable expectation of privacy over metadata, applies in the NSA’s bulk-metadata collection. The mass surveillance program differs so much from the one-time request dealt with by the 1979 case that it was of “little value” in assessing whether the metadata dragnet constitutes a fourth amendment search.

'Defying common sense'

In a decision likely to influence other federal courts hearing similar arguments from the ACLU, Leon wrote that the Guardian’s disclosure of the NSA’s bulk telephone records collection means that citizens now have standing to challenge it in court, since they can demonstrate for the first time that the government is collecting their phone data.

“The government asks me to find that plaintiffs lack standing based on the theoretical possibility that NSA has collected a universe of metadata so incomplete that the program could not possibly serve its putative function,” Leon wrote. “Candor of this type defies common sense and does not exactly inspire confidence!”

Leon also struck a blow for judicial review of government surveillance practices even when Congress explicitly restricts the ability of citizens to sue for relief. “While Congress has great latitude to create statutory schemes like Fisa,” he wrote, referring to the seminal 1978 surveillance law, “it may not hang a cloak of secrecy over the constitution.”

The case will almost certainly be heard next by the US court of appeals for the District of Columbia circuit, recently bolstered with two new liberal justices following a change in Senate rules relating to confirmation votes. Were the appeal court to uphold the ruling, the Department of Justice would seek another stay, pending a final verdict from the US supreme court or a "bench" decision by all justices on the appeal court.

In his ruling on Monday, Judge Leon predicted the process would take six months. He urged the government to take that time to prepare for an eventual defeat. “I fully expect that during the appellate process, which will consume at least the next six months, the government will take whatever steps necessary to prepare itself to comply with this order when, and if, it is upheld,” wrote Leon in his opinion.

“Suffice it to say, requesting further time to comply with this order months from now will not be well received and could result in collateral sanctions.”

The three DC appeal court judges who will first hear the case are chosen are random from the bench, currently comprising 10 justices.

However, it may prove a test of new Obama appointees, Patricia Millett and Nina Pillard, who were confirmed by the Senate last week in the face of bitter opposition from Republicans who said the administration was trying to “pack the court” with like-minded justices. A third, Robert Leon Wilkins, awaits confirmation by the Senate.

Though known as a straight-shooter when it comes to interpreting the law, Pillard, a Georgetown law professor, is married to prominent NSA critic and academic David Cole, who has argued that privacy is a “human right”.