The Justice Department under Attorney General Jeff Sessions had sued California over its sanctuary laws. (Jonathan Ernst/Reuters)

A federal judge on Thursday mostly rejected a bid by the Justice Department to block California’s “sanctuary state” laws, which enact policies friendly to undocumented immigrants.

In a 60-page ruling, U.S. District Judge John A. Mendez said most of the laws, which limit how state businesses and law enforcement agencies can work with federal immigration authorities, are “permissible exercises of California’s sovereign power.”

The judge said California was within its rights to allow state authorities to inspect immigrant detention facilities, and to bar state law enforcement agencies from providing release dates or other personal information to federal immigration authorities. He blocked portions of one law which imposed heavy fines on businesses that gave immigration authorities access to their facilities and records without a court order.

California Attorney General Xavier Becerra (D) hailed the decision as “a strong ruling against federal government overreach.”

“The Constitution gives the people of California, not the Trump administration, the power to decide how we will provide for our public safety and general welfare,” he said. “California’s laws work in concert — not conflict — with federal law.”

Justice Department spokesman Devin O’Malley, meanwhile, said the judge stopping the state from fining employers who cooperated with immigration authorities was “a major victory for private employers in California.”

“While we are disappointed that California’s other laws designed to protect criminal aliens were not yet halted, the Justice Department will continue to seek out and fight unjust policies that threaten public safety,” O’Malley said.

The Justice Department had filed a suit to block the California sanctuary laws in March, arguing that the measures obstructed enforcement of federal law and harmed public safety. They took aim specifically at three bills, which allowed for state review of immigrant detention facilities; restricted the information state law enforcement could share with immigration authorities; and imposed the fines on employers and required them to give notice of immigration inspection.

Mendez blocked three sections of the latter bill — though not the one having to do with providing notice — after finding that they “impermissibly infringed on the sovereignty of the United States.”

“The Court finds that a law which imposes monetary penalties on an employer solely because that employer voluntarily consents to federal immigration enforcement’s entry into nonpublic areas of their place of business or access to their employment records impermissibly discriminates against those who choose to deal with the Federal Government,” Mendez wrote.

Mendez, though, was skeptical of the government’s arguments about the other laws. While the federal government might like California to help more in cracking down on illegal immigration, he said it was “entirely reasonable” for state leaders to have determined that “assisting immigration enforcement in any way, even in purportedly passive ways like releasing information and transferring custody, is a detrimental use of state law enforcement resources.”

The state, he said, was not blocking immigration enforcement by not offering to help.

“Standing aside does not equate to standing in the way,” Mendez wrote.

Mendez wrote that he had reached his decision “without concern for any possible political consequences,” which he said was “a luxury, of course, that members of the other two branches of government do not share.” He concluded with a plea to the legislative and executive branches to “set aside the partisan and polarizing politics dominating the current immigration debate and work in a cooperative and bipartisan fashion toward drafting and passing legislation that addresses this critical political issue.”

“Our Nation deserves it,” he wrote. “Our Constitution demands it.”