A federal judge ruled Wednesday that a nonprofit group’s bid to open a site in Philadelphia where people can inject drugs under medical supervision does not violate federal law, an unprecedented decision that could affect the way cities across the country address the opioid crisis.

U.S. District Judge Gerald A. McHugh wrote that a provision of the Controlled Substances Act aimed at closing crack houses does not apply to the nonprofit organization’s bid to aid opioid abusers in Philadelphia’s drug-ravaged Kensington section.

“No credible argument can be made that facilities such as safe injection sites were within the contemplation of Congress” when lawmakers adopted the initial drug law in 1986 or when they amended it in 2003, McHugh wrote.

Cities across the United States, including Denver, Seattle, San Francisco and New York, have considered opening such facilities but have been stymied by the federal law and the Justice Department’s vow to halt any project of its kind.

Safehouse, a nonprofit organization that has the support of Philadelphia officials and former governor Ed Rendell, who sits on its board, decided to press forward nonetheless. The Justice Department sued in February to halt the project, leading to McHugh’s decision Wednesday.

“We’re grateful the judge agreed with us that federal law allows Safehouse to open a facility for the purpose of saving lives and preventing overdose deaths,” Ronda Goldfein, Safehouse’s vice president and executive director of the AIDS Law Project of Pennsylvania, said in an email. “This is a major step forward that lays the legal groundwork for moving ahead with this critical public health intervention.”

Deputy Attorney General Jeffrey A. Rosen said the Justice Department is “disappointed in the court’s ruling and will take all available steps to pursue further judicial review.”

He said that “any attempt to open illicit drug injection sites in other jurisdictions while this case is pending will continue to be met with immediate action by the department.”

Supervised injection sites are widespread in Canada and Europe where, advocates and researchers say, they have saved thousands of lives of people who use opioids and have directed some of them into treatment.

Typically, a site is stocked with naloxone, the antidote to overdoses of illegal fentanyl, and heroin, as well as oxygen, which helps revive overdose victims. Users bring in drugs obtained on the street and are monitored as they inject or smoke the drugs in an effort to prevent overdoses. Some sites also provide clean syringes, matches for cooking heroin, elastic strips to tie off veins, water to dilute drugs and other provisions.

Even as the opioid epidemic has killed more than 400,000 people over the past two decadesEfforts to open a similar facility in the United States have been blocked by the Justice Department’s adamant opposition.

In September 2018, then-Deputy Attorney General Rod J. Rosenstein wrote in a New York Times opinion column that “because federal law clearly prohibits injection sites, cities and counties should expect the Department of Justice to meet the opening of any injection site with swift and aggressive action.”

But McHugh wrote that “I cannot conclude that Safehouse has, as a significant purpose, the objective of facilitating drug use. Safehouse plans to make a place available for the purposes of reducing the harm of drug use, administering medical care, encouraging drug treatment and connecting participants with social services.”

The plans also have run into concerns from some residents of cities who fear that the facilities will become magnets for drug users in their neighborhoods.

In Philadelphia, where more than 1,000 people have died of drug overdoses in each of the past two years, Safehouse would open in a neighborhood that has one of the most active open-air heroin markets in the country. In addition to attempting to prevent overdoses, Safehouse would provide sterile equipment, fentanyl test strips, medically assisted drug treatment and other kinds of medical care.

But it is not clear how soon Safehouse might be able to open. “The judge’s decision is not a final judgment but lays the groundwork for us to move forward,” Goldfein said. When a final decision is issued, the government could again seek to block the project and McHugh and an appellate court would both have to decide whether to allow it, she said.