U.S. Immigration and Customs Enforcement has signed four multimillion-dollar contracts with several private prison companies to operate detention centers across California over the next five years, just days before a California law takes effect to ban new private-prison contracts.

The agency secured the contracts on Dec. 20 to continue to detain thousands of immigrants in existing facilities near Los Angeles and San Diego and to add about 2,000 beds in three additional facilities, according to a government website. The contracts with GEO Group, CoreCivic, and Management and Training Corp. will last five years, with the possibility of two five-year renewals.

AB32, by Assemblyman Rob Bonta, D-Alameda, prohibits the state or any other entity from entering into or renewing of contracts with private prison companies after Jan. 1, unless it’s necessary to comply with a court-ordered population cap. Under the bill, private prisons would be phased out completely by 2028.

Although ICE officials said their new contracts are not affected by AB32, critics lambasted the move.

“The terms of the contract, combined with the expanded number of beds, to us is truly an escalation of the partnership between ICE and private prisons to arrest and terrorize communities in California,” said Jackie Gonzalez, policy director for Immigrant Defense Advocates, a Sacramento-based organization that focuses on policy work to protect immigrant rights and end detention.

The signing of the contracts comes after immigration advocates and Democratic leaders expressed concern about the solicitation process ICE used to attract bids for the detention space. They alleged it violated federal procurement law and catered to the three corporations already running facilities across the state.

It’s the latest chapter in a contentious battle between the Trump administration and a sanctuary state that has rejected the president’s hardline immigration policies.

ICE officials on Monday said the new contracts comply with federal contract and acquisition regulations.

They also criticized California’s efforts to protect undocumented immigrants.

“State laws aimed at obstructing federal law enforcement are inappropriate and harmful,” ICE spokeswoman Paige Hughes said in a written statement. “Policymakers who strive to make it more difficult to remove dangerous criminal aliens and aim to stop the cooperation of local officials and business partners, harm the very communities whose welfare they have sworn to protect.”

The agency’s announcement on a government website for federal awards shows two five-year contracts for “housekeeping-guard” and “security guards and patrol services” with GEO Group for a total of $15 million, one with Management and Training for $7.1 million, and with CoreCivic for $7.3 million.

The three companies operate four federal immigration detention centers in California, housing more than 4,000 detainees: GEO Group runs facilities in Bakersfield and Adelanto in San Bernardino County; CoreCivic runs one in San Diego; and Management and Training Corp. runs one in Calexico in Imperial County.

ICE posted a solicitation for bids for detention space just five days after Gov. Gavin Newsom signed AB32 on Oct 11.

A private prison may continue its operations if it has a contract with a government agency that went into effect before Jan. 1.

Bonta on Monday said the contracts show a “dogged commitment by ICE to give away taxpayer dollars.”

“It’s sad; it never ceases to be shocking in terms of their lack of values and their willingness to hurt people and continue using these facilities where the rate of death is higher, where there’s a lack of health care,” he continued.

An investigation by the USA Today Network revealed widespread sexual assault, use of physical force, poor medical care and deaths at detention facilities overseen by ICE.

Immigration advocates and Democratic lawmakers expressed “serious concern” last month about the timing of ICE’s solicitation and the process it used to secure new detention space across the state, saying it favored existing companies.

In a letter addressed to ICE and the Department of Homeland Security, lawmakers said several aspects of the agency’s solicitation raised concern, including the length of the contract and the fact that bidders were given only two weeks to respond, compared with at least 30 days normally. Those factors — and a requirement that the new facilities be “turnkey ready” — make it clear ICE is favoring the corporations it already works with, they argued.

The group of two Democratic U.S. senators and 19 House members included Sens. Dianne Feinstein and Kamala Harris, and Rep. Zoe Lofgren of San Jose, Ro Khanna of Fremont and Mark DeSaulnier of Concord.

In a press release Monday, Geo Group announced its two new contracts with ICE. The Florida-based prison corporation will continue to run the Mesa Verde and Adelanto detention facilities, and also incorporate three of its other correctional facilities as annexes: the 700-bed Central Valley, 750-bed Desert View and 700-bed Golden State facilities.

“These contracts will help the agency meet its need for processing center beds in California, avoiding the need to send individuals to other states away from their families and legal counsel, while also supporting 1,200 jobs in communities we have partnered with for 30 years,” a spokesman said in a statement.

A rep for CoreCivic deferred questions to ICE. A spokeswoman for Management and Training Corp. did not reply to a request for comment.

Tatiana Sanchez is a San Francisco Chronicle staff writer. Email: tatiana.sanchez@sfchronicle.com Twitter: @TatianaYSanchez.