A federal appeals court panel ruled on Thursday that the NSA’s bulk collection of metadata of phone calls to and from Americans is not authorized by Section 215 of the USA Patriot Act, throwing out the government’s legal justification for the surveillance program exposed by NSA whistleblower Edward Snowden nearly two years ago.

Judge Gerard E. Lynch, writing the opinion for the unanimous three-judge panel of the Second Circuit Court of Appeals in New York, described as “unprecedented and unwarranted” the government’s argument that the all-encompassing collection of phone records was allowed because it was “relevant” to an authorized investigation.

The case was brought by the American Civil Liberties Union, and ACLU attorney Alex Abdo told The Intercept, “This ruling should make clear, once and for all, that the NSA’s bulk collection of Americans’ phone records is unlawful. And it should cast into doubt the unknown number of other mass surveillance operations of the NSA that rely on a similarly flawed interpretation of the law.”

As Lynch wrote in the court’s opinion: “To obtain a § 215 order, the government must provide the FISC [Foreign Intelligence Surveillance Court] with ‘a statement of facts showing that there are reasonable grounds to believe that the tangible things sought are relevant to an authorized investigation (other than a threat assessment).'”

Lynch continued:

The government emphasizes that “relevance” is an extremely generous standard, particularly in the context of the grand jury investigations to which the statute analogizes orders under § 215. Appellants argue that relevance is not an unlimited concept, and that the government’s own use (or non-use) of the records obtained demonstrates that most of the records sought are not relevant to any particular investigation.”

Indeed, he noted:

The records demanded are all-encompassing; the government does not even suggest that all of the records sought, or even necessarily any of them, are relevant to any specific defined inquiry.

And therefore, he concluded:

We agree with appellants that such an expansive concept of “relevance” is unprecedented and unwarranted.

The panel rejected the government’s argument that the ACLU lacked standing because it couldn’t prove that any one person’s records, sitting in a searchable database, had been reviewed by government officials. But whether it’s a machine or a person doing the searching doesn’t matter, Lynch wrote:

[T]he government admits that, when it queries its database, its computers search all of the material stored in the database in order to identify records that match the search term. In doing so, it necessarily searches appellants’ records electronically, even if such a search does not return appellants’ records for close review by a human agent. There is no question that an equivalent manual review of the records, in search of connections to a suspect person or telephone, would confer standing even on the government’s analysis. That the search is conducted by a machine might lessen the intrusion, but does not deprive appellants of standing to object to the collection and review of their data.

This could become an important precedent in a legal review of the NSA’s ability to automatically turn voice into text, which I disclosed on Tuesday, based on more documents from the Snowden archive.

The court’s rebuttal of the government’s argument that Congress wanted bulk collection kept secret from the public is quietly blistering:

The government has pointed to no affirmative evidence, whether “clear and convincing” or “fairly discernible,” that suggests that Congress intended to preclude judicial review. Indeed, the government’s argument from secrecy suggests that Congress did not contemplate a situation in which targets of § 215 orders would become aware of those orders on anything resembling the scale that they now have. That revelation, of course, came to pass only because of an unprecedented leak of classified information.

The court did not officially rule on whether the program is unconstitutional, because it ruled it illegal on a statutory basis. But, Lynch wrote: “The seriousness of the constitutional concerns, however, has some bearing on what we hold today, and on the consequences of that holding.”

The primary author of the Patriot Act, Rep. Jim Sensenbrenner, R-Wisc., has said that neither he nor anyone else imagined the law would be used for bulk domestic surveillance. “How can every call that every American makes or receives be relevant to a specific investigation?” Sensenbrenner asked, shortly after Snowden revealed the program.

And as Lynch wrote in the opinion: “Congress cannot reasonably be said to have ratified a program of which many members of Congress – and all members of the public – were not aware.”

In a concurring opinion, Judge Robert D. Sack wrote:

Considering the issue of advocacy in the context of deliberations involving alleged state secrets, and, more broadly, the “leak” by Edward Snowden that led to this litigation, calls to mind the disclosures by Daniel Ellsberg that gave rise to the legendary “Pentagon Papers” litigation

The decision sends the matter back to the District Court level for “further proceedings consistent with this opinion,” adding to the doubts about the future of the one program that Congress appeared poised to end through legislation that had White House support. The USA Freedom act calls for the bulk collection of Americans’ phone records by the NSA to be replaced with a more selective approach in which the agency would collect from communications companies only records that match certain terms.

Three Patriot Act provisions, including Section 215, are set to expire on June 1. The USA Freedom Act would amend that section. Senate Majority Leader Mitch McConnell has proposed a full reauthorization of the Act as is. But as American University Law Professor Steve Vladeck points out: