NEW YORK (Reuters) - A U.S. spying program that systematically collects millions of Americans’ phone records is illegal, a federal appeals court ruled on Thursday, putting pressure on Congress to quickly decide whether to replace or end the controversial anti-terrorism surveillance.

An undated aerial handout photo shows the National Security Agency (NSA) headquarters building in Fort Meade, Maryland. REUTERS/NSA/Handout/Files

Ruling on a program revealed by former government security contractor Edward Snowden, the 2nd U.S. Circuit Court of Appeals in Manhattan said the Patriot Act did not authorize the National Security Agency to collect Americans’ calling records in bulk.

Circuit Judge Gerard Lynch wrote for a three-judge panel that Section 215, which addresses the FBI’s ability to gather business records, could not be interpreted to have permitted the NSA to collect a “staggering” amount of phone records, contrary to claims by the Bush and Obama administrations.

“Such expansive development of government repositories of formerly private records would be an unprecedented contraction of the privacy expectations of all Americans,” Lynch wrote in a 97-page decision. “We would expect such a momentous decision to be preceded by substantial debate, and expressed in unmistakable language. There is no evidence of such a debate.”

The appeals court did not rule on whether the surveillance violated the U.S. Constitution.

It also declined to halt the program, noting that parts of the Patriot Act including Section 215 expire on June 1.

Lynch said it was “prudent” to give Congress a chance to decide what surveillance is permissible, given the national security interests at stake.

Enacted after the Sept. 11, 2001 attacks, the Patriot Act gives the government broad tools to investigate terrorism.

Thursday’s decision voided a December 2013 ruling in which U.S. District Judge William Pauley in Manhattan found the NSA program lawful. The appeals court sent the case back to him for further review.

NEXT STEP IN CONGRESS

Snowden, a former NSA contractor who lives as a fugitive in Russia, in June 2013 exposed the agency’s collection of “bulk telephony metadata.” This data includes the existence and duration of calls made, but not the content of conversations.

U.S. Attorney General Loretta Lynch said at a Senate budget hearing on Thursday that NSA data collection was a “vital tool in our national security arsenal,” and that she was unaware of privacy violations under its existing program.

Snowden could not immediately be reached for comment.

The 2nd Circuit is the first federal appeals court to rule on the NSA program’s legality. Federal appeals courts in Washington, D.C. and California are also weighing the matter.

While the government could appeal Thursday’s decision, it will likely wait for Congress.

If Congress revamps the NSA program, then courts may need to review what it does. And if Congress reauthorizes Section 215, there could be further litigation that may ultimately require the Supreme Court’s attention.

Scott Vernick, chair of the privacy and data security practice at Fox Rothschild in Philadelphia, said Congress may struggle to reach a consensus given how “the pendulum in this country is swinging toward privacy.”

Ned Price, a spokesman for the White House’s National Security Council, said President Barack Obama wants to end the NSA program, and is encouraged by the “good progress” on Capitol Hill to find an alternative that preserves its “essential capabilities.”

Last week, the House Judiciary Committee voted 25-2 to end the bulk collection of telephone data through the USA Freedom Act. The bill is expected to pass the full House, and the White House has signaled support for it.

While a similar bipartisan bill is pending in the Senate, Majority Leader Mitch McConnell and Intelligence Committee chair Richard Burr, both Republicans, have proposed extending Section 215 and other parts of the Patriot Act through 2020.

Harry Reid, the Nevada Democrat and Senate minority leader, rejected that alternative, calling it “the height of irresponsibility to extend these illegal spying powers when we could pass bipartisan reform into law instead.”

The existing NSA program has repeatedly been approved in secret by a national security court established under a 1978 law, the Foreign Intelligence Surveillance Act.

“FISA has been critically important in keeping us safe in America,” McConnell said on Thursday.

COUNTER-PUNCH

Senators from both sides of the aisle, and who are running for president, used Twitter to welcome Thursday’s decision.

Sen. Rand Paul, a Kentucky Republican, said “phone records of law abiding citizens are none of the NSA’s business!” while Sen. Bernie Sanders, a Vermont Democrat, said “the NSA is out of control and operating in an unconstitutional manner.”

In upholding the NSA program in 2013, Pauley had called it a government “counter-punch” to terrorism at home and abroad.

Pauley ruled 11 days after U.S. District Judge Richard Leon in Washington, D.C. said the “almost Orwellian” program might violate Fourth Amendment limitations on warrantless searches.

Leon issued an injunction to block the program, but put it on hold pending appeal.

While the 2nd Circuit did not resolve the Fourth Amendment issues, Judge Lynch did note the “seriousness” of constitutional concerns over “the extent to which modern technology alters our traditional expectations of privacy.”

ACLU lawyer Alex Abdo welcomed Thursday’s decision.

“Mass surveillance does not make us any safer, and it is fundamentally incompatible with the privacy necessary in a free society,” he said.

The case is American Civil Liberties Union et al v. Clapper et al, 2nd U.S. Circuit Court of Appeals, No. 14-42.