A federal appeals court ruled a National Security Agency program that collects phone records on millions of Americans is illegal, intensifying a fight in Congress over extending the soon-to-expire surveillance effort.

A three-judge panel of the Second U.S. Circuit Court of Appeals in New York eviscerated many of the legal theories under which the U.S. government has expanded surveillance since the Sept. 11, 2001, terror attacks. The judges didn’t address whether the NSA program violates constitutional privacy rights, as some groups allege, but found the Patriot Act language used by the Bush and Obama administrations to justify the program wasn’t meant to allow such mass data gathering.

“The statutes to which the government points have never been interpreted to authorize anything approaching the breadth of the sweeping surveillance at issue here,” the judges wrote in their 97-page ruling. “The sheer volume of information sought is staggering.”

The NSA has used Section 215 of the Patriot Act—a 2001 law that expanded the government’s authority to search for terror suspects—to justify collecting records of nearly every call made in the U.S. The program gathers metadata—the number called, the time and the duration of the call—but not the content of the conversation. The intent is to look for possible contacts among terror suspects.

The scope of the program was revealed in 2013 when former NSA contractor Edward Snowden leaked documents describing it, reigniting a debate over the data collection and whether it infringes on Americans’ privacy.