U.S. Bankruptcy Judge Kevin Gross seemed eager Wednesday to approve the controversial sale of bankrupt Hahnemann University Hospital’s medical resident training program to Thomas Jefferson University Hospitals Inc. for $55 million over the objection of federal regulators.

But after an all-day hearing in Wilmington, Gross announced that he would rule Thursday from the bench on the sale that Hahnemann’s lawyers have called a “game-changer” for the bankrupt hospital, which in the beginning appeared to have little chance of scraping together much money to pay unsecured creditors.

“If you win, this bankruptcy fails,” Gross told Marc S. Sacks, a U.S. Department of Justice attorney arguing for the Centers for Medicare and Medicaid Services (CMS) — the federal agency that oversees the residency program — that the sale is illegal. “I don’t think the government wants this bankruptcy case to fail on its arguments,” Gross said, advising Sacks to reach an agreement with lawyers for Hahnemann and Jefferson during a lunch break.

Sacks did not see any room for reaching such a negotiated settlement, which would guarantee that the more than 500 residency slots would stay in the Philadelphia region. Besides the risk of the region, a health-care hub, losing hundreds of highly sought doctors-in-training paid for by Medicare, a ruling in favor of CMS would force Hahnemann’s parent company to look for other ways to raise the money needed to begin paying off creditors.

“We need to stand on our legal objection,” Sacks responded, “even if that means you rule against us.”

Thursday’s ruling by Gross will be a turning point in the Hahnemann and St. Christopher’s bankruptcy filed June 30, about 18 months after California investment banker Joel Freedman bought the hospitals for $170 million from Tenet Healthcare Corp.

Couched in clever legal gymnastics, arguments Wednesday revolved around conflicts between bankruptcy code and complex federal law and regulations governing Medicare, the massive health insurance program for the elderly. Hahnemann’s medical residency program is part of its Medicare agreement with the CMS.

“I think there are dueling prerogatives,” Patrick A. Jackson, a Drinker Biddle & Reath LLP lawyer representing Jefferson, told the judge.

Just as CMS has the right to run the Medicare program as it sees fit within the constraints of its legal authority, “the court has institutional prerogative,” Jackson said, adding that bankruptcy law is equal to the laws governing Medicare and can trump certain aspects of nonbankruptcy law.

“There are lots of tools in the court’s toolkit,” Jackson said, urging Gross to approve the sale over CMS’s objection.

The overarching argument of Hahnemann and Jefferson was that nothing in federal laws or regulations expressly prohibits the sale of Hahnemann’s residency program.

Critics of the unprecedented proposal say the sale could set a precedent for the “cherry picking” of highly sought-after residency programs from distressed hospitals.

Sacks’ legal starting point was a provision in the Affordable Care Act that established a procedure for CMS to redistribute residency slots when a teaching hospital closes. The first priority goes to hospitals in the same area as the closed hospital. Such a redistribution has happened 14 times since 2010, when the law was passed, Sacks said. Jefferson and Abington Health, one of the systems Jefferson has acquired since 2015, have bid on and won resident slots under that process. “You don’t have to pay for those residency slots,” Sacks said.

“If Hahnemann is closing, Congress is saying what happens to those residency slots,” he said.

Even though Hahnemann hasn’t had inpatients since late July, its lawyers seized on the notion that the hospital is still in business because it is still aiding former patients who call in for their records or seek help finding a new place to go for care.

“We are selling the provider agreement before we cease business,” said Mark Minuti, Hahnemann’s lead bankruptcy lawyer and a partner at Saul Ewing.

The hospital’s official closing date, under a state-approved plan, is Friday, when Jefferson is supposed to complete its purchase of the residency program.

Under the CMS doctor-training program, each teaching hospital has a cap on the number of residents CMS will pay for. Hospitals are allowed to hire more residents, but have to pay for them out of their own pockets. That’s what Jefferson has done, but it hasn’t said whether it would actually increase the number of residents it employs or substitute the acquired residents that are funded by CMS for those it already employs.

Lawyers called the sale of the residency program a creative way to salvage value from a perennially money-losing hospital.

An attempt to sell Hahnemann as an operating hospital during a few weeks in June failed. That was just before Hahnemann came too close to running out of money to safely operate, leading to the decision to close, Allen Wilen, the chief restructuring officer for Hahnemann’s parent company, testified Wednesday.

“It has systematic problems and systematic losses and capex [capital expenditure] needs,” Wilen said, making it so “you can’t operate this hospital at a profit.”

Since then, two companies, KPC Group and SBJ Group, which say they would like a chance to bid on Hahnemann as a going concern, have tried to insert themselves in the process. KPC, from California, even said during Wednesday’s hearing that it would be willing to pay $60 million for the residency program alone, with the intention of reopening the hospital.

“We’re here because we think we can provide a better outcome,” a lawyer for KPC said.

Gross said it was too late: “The auction closed.”

A separate auction for St. Christopher’s is scheduled for Sept. 18. Potential bidders for the North Philadelphia safety-net hospital include a team of Tower Health and Drexel University and a consortium comprised of Einstein Healthcare Network, Jefferson Health, Philadelphia College of Osteopathic Medicine, and Temple University Health System.