The absolute best political compromise is one where even if everything goes wrong, there’s someone else out there to blame.

Which brings us to the prison deal Gov. Jerry Brown cut with state Senate leader Darrell Steinberg this week.

For those who haven’t been following, judges all the way to the U.S. Supreme Court have ruled that overcrowding in California prisons violates inmates’ rights and needs to be fixed right now.

And “right now” means that by Jan. 1, California needs to have about 8,000 fewer inmates in its various state pens.

Brown, after years of dragging his feet and arguing unsuccessfully that California has done everything it needs to comply, reluctantly proposed that the state spend $315 million this year and another $400 million next year to move inmates to cells outside of the state prison system.

Steinberg argued instead that the state instead should spend $200 million to improve mental health and rehabilitation programs for ex-cons, which would cut the prison population over time by keeping them from returning to prison. He also would ask the federal judges to give the state three more years to comply so his program had time to work.

In the great tradition of California political compromises, Brown and Steinberg decided to do both.

The new deal, now on the governor’s desk as SB 105, gives Brown the $315 million he needs to transfer inmates to private and out-of-state prisons. But now that will only happen if Steinberg can’t convince the three federal judges overseeing the prison suit to give California time for the rehab programs to work.

For Brown, it’s a great solution. He doesn’t want to spend the  $315 million, but he’s not anxious to spend the rest of his term on the wrong side of iron bars, as the judges have none-too-subtly suggested could happen if he keeps ignoring their orders.

So let Steinberg take a shot. If it works, great. The state saves money and the governor gets a reputation as someone willing to deal. If it doesn’t, Brown still gets the money he needs to comply with the court order and stay out of the slammer.

It’s not a bad deal for Steinberg, either.  If the judges go along, he’s the one who succeeded where the governor couldn’t. If they don’t, well, he did what he could.

So far, it’s worked wonderfully well for the two Democrats.  When you have Senate Republican leader Bob Huff talking up the deal and GOP state Sen. Tom Berryhill saying it’s a great compromise and that “a lot of credit has to go to our leadership,” what’s not to like?

Best of all, both scenarios avoid the mass release of thousands of bad guys into communities across California, which would be a political time bomb for Democrats, who would be waiting nervously for the inevitable day when one of those former inmates did something horrible enough to make the front pages of the state’s newspapers.

And if villains are needed in this piece, there are always the judges, who can be denounced as unelected, out-of-touch and more concerned with the rights of murders and rapists than the safety of law-abiding Californians.

While Brown has said that there “are little smoke signals emanating from the mountaintops” suggesting that the judges may be willing to deal, Steinberg’s plan also requires that the attorneys representing the inmates fold what so far has been a winning hand.

Right now, the judges have an order calling for California to cut the prison population by the end of the year. So far, no one has explained why the attorneys pushing for those reductions would be interested in extending that date for another three years, especially since that original court order was issued in 2009.

And as for those “little smoke signals” Brown talked about, most of the smoke has been coming from the ears of Judge Stephen Reinhardt, who has become increasingly irate about what he sees as Brown’s continuing and willful delays in implementing the court order.

But all that’s for another day. Right now, Brown can sign the prison bill amid loud huzzahs from Democrats and Republicans, secure in the knowledge that “who knows, it might even work.”

John Wildermuth is a longtime writer on California politics.