California’s ban on private prisons is being challenged by the federal government, which confines about 7,000 prisoners and immigrants in privately owned facilities in the state and says California has no right to regulate their placement.

The law prohibits new contracts with private prison companies in the state and also bars renewal of existing contracts, a phase-out that would eliminate privately owned detention facilities in the state by 2028. California now pays the Florida-based GEO Group $60 million a year to hold just over 2,000 inmates in four private prisons in Kern and San Bernardino counties.

Private prisons generally cost less than state-run facilities and are not as closely regulated, leading to health and safety concerns. A U.S. Justice Department report in 2016 found a higher rate of assaults by inmates on guards and fellow prisoners in private prisons. A video obtained by NPR shows guards at a GEO Group facility in Adelanto (San Bernardino County) pepper-spraying and dragging away immigrant detainees who were on a hunger strike in 2017.

The ban sends a message that “we vehemently oppose the practice of profiteering off the backs of Californians in custody,” Assemblyman Rob Bonta, D-Alameda, said in October after Gov. Gavin Newsom signed his AB32 into law. Newsom had promised to end private prisons in his inaugural address last year, saying they contribute to excessive incarceration.

But in a filing Wednesday asking a federal judge in San Diego to prevent the law from applying to federal prisoners and detained immigrants, President Trump’s Justice Department said AB32 had overstepped the state’s power to regulate its own affairs.

California is free to ban private prisons for state inmates, “but it cannot dictate that choice for the United States,” government lawyers said. They said federal law authorizes three government agencies to contract with private companies for detention facilities: the U.S. Bureau of Prisons, for federal inmates; the U.S. Marshals Service, for federal defendants held in custody while awaiting trial; and Immigration and Customs Enforcement, for migrants facing deportation.

Because those agencies have no space available in their own prisons and detention centers in California, most of the 7,000 current inmates would be sent to private prisons in other states, “isolating prisoners and detainees from their families,” the court filing said.

It also said relocating inmates, and transporting them back to California for court hearings, would be expensive for the government and potentially disruptive to legal proceedings, causing weeks of delays.

“These injuries could cripple federal law enforcement operations in California,” Justice Department lawyers said.

In addition, they contended the new law is discriminatory because it allows the state to use private detention facilities for a few categories of inmates, including those receiving mental health treatment and some juveniles in custody, and to comply with federal court limits on the population of California’s crowded state prisons. No such exemptions apply to federal inmates.

Bonta called the government’s lawsuit “desperate and baseless.” In a statement, he said his legislation would end prison operations in California by “corporations (that) answer to Wall Street, disregard human rights, hurt, harm, abuse and neglect our people, and conflict with our California values.”

Bob Egelko is a San Francisco Chronicle staff writer. Email: begelko@sfchronicle.com Twitter: @BobEgelko