Washington CNN  — 

A federal appeals court ruled on Thursday that the telephone metadata collection program, under which the National Security Agency gathers up millions of phone records on an ongoing daily basis, is illegal under the Patriot Act.

The government has argued it has the power to carry forward with the program under a section of the Patriot Act, which expires in June. Lawmakers are locked in a debate on whether or how to renew the authority, which was first passed shortly after the Sept. 11, 2001 terror attacks on New York and Washington, but has been renewed by both Presidents Bush and Obama in the intervening years.

Documents confirming the program’s existence were first revealed in June of 2013 with the leaks by former government contractor Edward Snowden.

Judicial rebuke

The decision by a three-judge panel that the phone record collection program, which was mostly secret for nearly a decade, is not supported by the current version of the law, will certainly enter into the brewing political debate over renewing it.

RELATED: Why the NSA decision matters

Judge Gerard E. Lynch, writing for a three judge panel of the Second Circuit Court of Appeals, said the program “exceeds the scope of what Congress has authorized.”

Lynch wrote that the text of the Patriot Act “cannot bear the weight the government asks us to assign to it, and that it does not authorize the telephone metadata program.”

The Court did not address the larger question of whether the program is constitutional and sent the case back down to a lower court for further proceedings. It noted that the section of the Patriot Act that the government said authorized the law - Section 215 - is set to expire in early June.

“In light of the asserted national security interests at stake, we deem it prudent to pause to allow an opportunity for debate in Congress that may (or may not) profoundly alter the legal landscape,” Lynch wrote.

He was clearly concerned with the scope of the program. He wrote the “sheer volume of information sought is staggering.”

No clear path in Congress

Sen. Marco Rubio, the Florida Republican who is also running for president, defended the NSA program on the Senate floor shortly after the court decision was made public.

“A perception has been created, including by political figures who serve in this chamber, that the United States government is listening to your phone calls or going through your bills as a matter of course,” said Rubio. “That is absolutely and categorically false.”

The House is set to approve the USA Freedom Act, which would kill the NSA’s dragnet collection of phone metadata and reform the process by which government agencies petition the secret FISA court to obtain warrants to collect that data.

That bill was the result of a compromise between the top lawmakers pushing surveillance reform and the House Republican leadership, which has been loathe to accept broad reforms to the Patriot Act.

But the bill faces stiff opposition in the Senate where Senate Majority Leader Mitch McConnell has instead put forward a bill to fast-track the Patriot Act’s reauthorization largely as-is.​ McConnell has several allies in the fight to stave off reforms to the Patriot Act, including the top Republican on the Senate Intelligence Committee and security hawks like Sens. Lindsey Graham, R-South Carolina, Rubio, and Tom Cotton, R-Arkansas.

The court ruling could complicate McConnell’s plan to push to keep the authority for the government to collect and house the phone data.

“It pulls the rug out from under Sen. McConnell and Sen. Burr’s position,” said Sen. Chuck Schumer.

Long-secret phone program

The program gathers up bulk telephone records and conducts targeted searches on the data based on telephone numbers or other identifiers associated with terrorist organizations. Telephone metadata does not include the content of telephone conversations, but other details such as the length of the call, the originating phone number and the number called.

“This decision is a resounding victory for the rule of law,” said ACLU Staff Attorney Alex Abdo, who brought the challenge.”For years, the government secretly spied on millions of innocent Americans based on a shockingly broad interpretation of its authority. The court rightly rejected the government’s theory that it may stockpile information on all of us in case that information proves useful in the future. Mass surveillance does not make us any safer, and it is fundamentally incompatible with the privacy necessary in a free society, “he said.

The government has defended the program arguing it was necessary to maintain national security, and said that it was authorized by statute and the Constitution . The government stressed that the program doesn’t collect the content of any calls and is subject to oversight by the Department of Justice, the secret Foreign Intelligence Surveillance Court and Congress.

Sweeping loss for U.S. government in court

The ruling is a sweeping loss for the government that had contended in court papers that the program is meant as a “tool to facilitate counter-terrorism investigations —specifically, to ascertain whether international terrorist organizations are communicating with operatives in the United States.”

The government defended the program saying it operates on orders from the secret Foreign Intelligence Surveillance Court (FISC) — a court that Congress created to grant applications for surveillance orders in foreign intelligence investigations. In court papers, government lawyers had argued that sixteen different judges from the FISC on 37 separate occasions concluded that it is lawful for the government to obtain telecommunications companies’ business records that reflect the data concerning the time, duration, dialing and receiving information, but that don’t include the content of the calls.

Today’s order repudiates the findings by the FISC. In a footnote Lynch noted that the discrepancy between the appeals court ruling and those of the FISC might be “accounted for by our having received the benefit of an adversarial presentation on the issues. “

“We are in the process of evaluating the decision handed down this morning.,” said White House National Security Spokesman Ned Price in a statement.

Related: Despite Obama’s NSA changes, phone records still collected

“Without commenting on the ruling today, the President has been clear that he believes we should end the Section 215 bulk telephony metadata program as it currently exists by creating an alternative mechanism to preserve the program’s essential capabilities without the government holding the bulk data. We continue to work closely with members of Congress from both parties to do just that, and we have been encouraged by good progress on bipartisan, bicameral legislation that would implement these important reforms,” he said.

“This is a landmark ruling and a critically important decision, ” said Stephen I. Vladeck, Professor of Law American University, Washington College of Law and an analyst for CNN. “What it means going forward depends entirely on Congress, because this provision was set to expire June 1st anyway, ” he said.

CNN’s Jim Acosta, Ted Barrett and Jeremy Diamond contributed to this report.