The Justice Department ruled Tuesday that the U.S. Bureau of Prisons is not required to reimprison thousands of federal inmates who were granted home confinement to limit the spread of the coronavirus — even after the federal health emergency ends.

The decision reverses a January order issued in the final days of the Trump administration and allows the federal agency to avoid recalling prisoners en masse.

The BOP has released more than 36,000 to home confinement since Congress expanded the program at the start of the pandemic to help reduce the spread of the coronavirus in its jails. Many of those prisoners were near the end of their sentences and would have been released even without the pandemic, advocates say.

Nearly 8,000 are now on home confinement, according to the federal agency, with the rest either having finished their sentences or been sent back to prison for violating rules of the program. Advocates estimate that about 3,000 would be at risk of being returned to prison if the Trump-era order is not lifted.

Those who remain on home confinement can continue to reintegrate into society, living with loved ones, holding down jobs and abiding by specific restrictions that governed their release, officials said.

In a 15-page memo, Christopher H. Schroeder, an assistant attorney general in the Office of Legal Counsel, wrote that the Federal Bureau of Prisons has long exercised discretion about home confinement on an individual basis and that the agency must be allowed to avoid a “blanket, one-size-fits-all policy.”

When the pandemic health emergency is lifted, Schroeder wrote, the agency should not be required to “disrupt the community connections these prisoners have developed in aid of their eventual reentry.”

Prison reform advocates have petitioned the Biden administration for months to allow prisoners to remain on home confinement after the emergency is lifted. All of those released from jails under the provision were deemed “low risk,” federal officials said, and many are elderly and in poor health.

So far, 262 inmates and seven staffers have died from the coronavirus at BOP-managed facilities, along with 11 inmates who were on home confinement, according to the federal agency.

In a letter in April, 28 members of Congress — 27 Democrats and Rep. Kelly Armstrong (R-N.D.) — urged President Biden to “reverse the Trump administration’s cruel and misguided decision,” saying that a wholesale return of released inmates to prison “would harm families, waste tax dollars and undermine public safety.”

A Justice Department spokesman said Attorney General Merrick Garland ordered his staff to examine the issue after he studied the underlying statute. Garland met Tuesday with several inmates who had been released to home confinement under the pandemic-related Cares Act provisions to hear about their experiences, the spokesman said.

“Thousands of people on home confinement have reconnected with their families, have found gainful employment, and have followed the rules,” Garland said in a statement. “In light of today’s Office of Legal Counsel opinion, I have directed that the Department engage in a rulemaking process to ensure that the Department lives up to the letter and the spirit of the Cares Act.”

Kevin Ring, president of the nonprofit prisoner advocacy organization Families Against Mandatory Minimums, said he spoke with inmates who were overcome by emotion Tuesday after learning of the Justice Department’s decision.

“This cloud has been over their heads for 11 months,” since Biden took office, said Ring, who also spoke with Garland on Tuesday. “We tried to sound the alarm early and get the administration to do this. It was frustrating at times, but they got to the right result.”

Emily Singer, press secretary of Democracy Forward, called the Justice ruling “excellent news for thousands of people and families to get before the holidays.”