How did this happen?

The conventional wisdom was that Whole Woman’s Health v. Hellerstadt, the most significant abortion case in a quarter century, would end in a 4-4 deadlock, upholding Texas’s strict abortion regulations and causing the majority of the state’s clinics to close.

Instead, the Court went 5-3, striking down the law’s most onerous provisions and dooming a dozen states’ similar laws to oblivion. What happened?

Two words: Justice Kennedy.

Although the Court’s majority opinion was written by Justice Breyer, it is consistent with Justice Kennedy’s centrist jurisprudence, with its penchant for balancing tests, case-by-case analysis, and middle-of-the-road reasoning. Indeed, it strongly resembles Kennedy’s own opinion in last week’s affirmative action case, which upheld race-conscious admissions under certain circumstances, depending on the facts, and maybe sometimes but not others.

Whole Woman’s Health went similarly. For all the controversy, the question presented by the case was simple: whether Texas’s law, on its face meant to protect women’s health and safety, actually placed an “undue burden” on women seeking abortions.

Plaintiffs – supported by the American Medical Association and other professional organizations—alleged that there was no evidence that the law’s restrictions (in particular, requiring doctors to have admitting privileges at a nearby hospital and requiring clinics to meet the standards for surgical centers) would have any effect on women’s health. What they would effect is the availability of reproductive health care: 32 of Texas’s 42 clinics would close.

The State of Texas countered, saying that it’s not up to courts to weigh scientific evidence, and the Fifth Circuit Court of Appeals agreed. Under Supreme Court precedent, it ruled, courts defer to the findings of a legislature, and do not impute an unconstitutional reason (e.g. restricting abortion) when a legitimate one (e.g. protecting heath) is available.

(The case also presented a significant procedural question, the subject of Justice Alito’s dissent and several pages of the Court’s opinion – but the Court moved beyond it to address the merits of the claim.)

So, which is it? Defer to the Texas legislature, even though it relied on junk science? Or substitute the Court’s judgment for theirs?

It was pretty clear how the eight-person court – still with that gaping vacancy where the late Justice Scalia used to be – would rule. The conservatives (Roberts, Alito, Thomas) would side with Texas, the liberals (Breyer, Ginsburg, Kagan, Sotomayor) would side with the plaintiffs, and Justice Kennedy would be in the middle.

Most court-watchers thought Kennedy would side with the conservatives. True, he was one of the co-writers of 1992’s landmark opinion in Planned Parenthood v. Casey, which preserved abortion rights—again in a surprise vote – but allowed more restrictions than previously. But since then, Kennedy has generally upheld restrictions on abortion, and, for what it’s worth, has signaled that he is against abortion personally, perhaps as a matter of his Catholic faith.

But the more you look at Whole Woman’s Health, the more sense the result makes.

First, like Casey, it’s a balancing opinion. Yes, the Court held, states deserve deference—but not this much deference. Unlike the Fifth Circuit’s opinion, Justice Breyer’s listed 15 of the district court’s factual findings that the law would burden women seeking abortions, and cited a dozen expert opinions on its minimal health benefits. (For example, the rate of complications in abortions is less than 1 percent; existing requirements for abortion clinics would prevent virtually all foreseeable problems; and so on.) And then it balanced one against the other.

“In the face of no threat to women’s health, Texas seeks to force women to travel long distances to get abortions,” Justice Breyer wrote.

It’s easy to see this balancing, on-the-facts opinion as a compromise meant to get Justice Kennedy on board. It’s an opinion he could have written himself.

Second, consider the alternative. Had the Court deferred to Texas’s junk science, all a state would have to do is find a single doctor to state a point of view, and, presto, the Casey balancing tests are effectively written out of existence. That’s not the Kennedy way, which tends to get in the weeds and find a middle way.

And then there’s the judicial alternative. No one hates a 4-4 deadlock more than Supreme Court justices themselves. Whatever Senate Republicans may say, the justices know that their job is to decide cases and settle crucial questions of law. A one-sentence per curiam opinion of an “equally divided court” —such as the one we saw in last week’s immigration case—is an abject failure of that mission.

This is not to say that Justice Kennedy would go along with any opinion in order to avoid a deadlock. But we’ve seen the Court contort itself in far more inventive ways this term, like the Zubik v. Burwell case on Obamacare and religious exemptions, in which the Court proposed its own compromise solution and then wrote it into law. Working out a compromise in Whole Woman’s Health is a lot simpler than that.

That may also be why Justice Ginsburg wrote a separate, one-page concurring opinion in much stronger language than the majority’s. Though it will probably be remembered for its use of the French phrase faute de mieux (“in the absence of an alternative”), it was probably written to record Ginsburg’s strong rejection of Texas’s health rationale. “It is beyond rational belief that H.B. 2 could genuinely protect the health of women,” she wrote.

That’s not Kennedy-esque language.

Whole Woman’s Health could still have gone the other way; Justice Kennedy could have signed onto the dissent’s procedural objections, or, under the cover of a 4-4 per curiam opinion, avoided the contentious issue altogether.

But if we understand Casey, we can understand Whole Woman’s Health. For better or for worse, they are consistent with Justice Kennedy’s longstanding style of adjudicating cases: balancing facts, getting into the weeds, and finding a middle way. It may or may not be the preeminent model of Supreme Court jurisprudence, but it has once again left its mark on history.