The Obama administration is urging lawmakers to pass a bipartisan bill that would end the National Security Agency’s mass collection of Americans’ phone records, an effort that has been boosted by a federal appeals court’s ruling last week that the program was unlawful.

The White House’s support for the USA Freedom Act, which preserves the government’s ability to obtain more limited amounts of records, comes as the House is expected to pass it on Wednesday. That sets up a showdown in the Senate, where Majority Leader Mitch McConnell (R-Ky.) is backing another bill that would maintain the NSA program of mass collection and renew it through 2020.

The attorney general and the director of national intelligence are expected to issue soon a letter of support for the USA Freedom Act, saying that they do not think it will undermine national security while its proposed reforms will enhance Americans’ privacy.

There is a sense of urgency because time is running out for Congress to act on the issue. If lawmakers fail to pass a bill by June 1, the bulk collection of Americans’ phone records will automatically expire. The Obama administration has concluded that the USA Freedom Act is the best opportunity to maintain the government’s power to obtain records of terrorist suspects with some measure of speed.

“Last week’s judicial decision just underscores the need for Congress to take action now, so that these important national security authorities are not subject to continued uncertainty,” said National Security Council spokesman Edward Price.

The administration has long contended that the collection program was lawful. But after its existence was leaked in 2013 by former NSA contractor Edward Snowden, the public outcry forced President Obama to call for an end to the agency’s collection of so many records while seeking a way to preserve its access to the ones it needs. The government would serve a court order on phone companies for data on specific numbers or other “selection terms.”

The original program was begun in secret by the George W. Bush administration after the September 2001 terrorist attacks. The NSA collects from major U.S. phone companies all records of customers’ phone calls and their lengths and times, but not the content.

McConnell has support from the most hawkish members of his party conference, such as Sen. Marco Rubio (R-Fla.), a presidential candidate who defended current practices in a USA Today op-ed Monday.

But most analysts say that McConnell’s bill is likely to fail. Other Republican senators, including Rand Paul (Ky.), also a presidential candidate, and Mike Lee (Utah), want curbs placed on the NSA’s surveillance authority. Paul has said that he would filibuster any bill that extends that authority without reforms. Sen. Ron Wyden (D-Ore.) has vowed to do the same.

On Monday, Minority Leader Harry M. Reid (D-Nev.) urged McConnell to bring the House bill to the floor, saying it would be “irresponsible” to extend the current statute in light of the court ruling. “How can you reauthorize something that is illegal?” he said. “You can’t. You shouldn’t.”

Some former officials said that McConnell should take note of the modest value of the program. “How far out on a limb do you want to go for a program where the value is limited?’’ said one former national security official, who, like several others interviewed for this story, requested anonymity to speak candidly. “I’m not going to say it’s nonexistent, but the value is limited.”

The statute authorizing the program is known as Section 215 of the USA Patriot Act, which requires that records sought by the government be “relevant” to an authorized investigation to protect against foreign terrorism.

On Thursday, the U.S. Court of Appeals for the 2nd Circuit in New York ruled that the program violated the statute because the government’s collection of “all” call detail records by major U.S. phone companies cannot be said to be relevant to any particular investigation. Such an “expansive concept of ‘relevance’ is unprecedented and unwarranted,” said the opinion by a three-judge panel of the court.

Both the Bush and Obama administrations have argued that the statute indeed contemplates such broad collection. And nearly 20 judges from the secretive Foreign Intelligence Surveillance Court have agreed over the years.

But given the Obama administration’s goal of seeing the USA Freedom Act pass, the ruling is a boost. “It provides them the ammunition to say, ‘Look, if you want this [program] and you think there’s any value to this, this seems to be the legal way to do it,’ ” said the former national security official.

Some current and former intelligence officials are meanwhile expressing chagrin with the appeals court ruling, which declared the program illegal three weeks before the statute expires and then did not, as the former official said, “put their money where their mouth is” and issue an injunction to halt it.

“Everyone is angry and frustrated because I think there’s a sense that the opinion was a last-ditch attempt by three judges to insert themselves into the debate with nothing more than an advisory opinion,” said a former intelligence official. “This was just a purely political opinion and goes way beyond what judges are allowed to do.”

But former judge Patricia Wald, who served 20 years on the U.S. Court of Appeals for the District of Columbia Circuit and is a member of the executive branch watchdog Privacy and Civil Liberties Oversight Board, said such action is not unusual. She said that the New York appeals court’s decision not to issue an injunction at this point is more “an act of judicial restraint.”

In its ruling, the New York appeals court also rejected the government’s argument that Congress ratified the program by twice reauthorizing Section 215, noting that many members and the public were unaware of how the legislation was being interpreted. But that argument has come under fire in recent days from current and former officials who say that senior national security officials held many briefings for lawmakers on the program.

“They didn’t all show up,” said a second former intelligence official. “But all the members had every opportunity to review the pleadings and come to meetings to hear how ‘relevance’ was being interpreted.”