In October, this Supreme Court term looked like it could be a disaster. The Court had taken review of cases involving multiple hot-button issues that typically divide conservatives and liberals, and, as has been the case since 1972, the Court’s conservatives outnumbered its liberals. Abortion, affirmative action, public-union dues, President Obama’s immigration initiative, voting rights, and the Affordable Care Act (again) were all on the chopping block. Many observers predicted this would be the year the Roberts Court showed its full conservative strength, and the only question that remained was how devastating the results would be.

Then Justice Antonin Scalia died, and everything changed. There was no longer a conservative majority; instead, the Court was evenly divided, 4  –  4, between conservative and liberal justices. Lawyers preparing for their Court appearances changed their arguments; pundits adjusted their predictions. That a single justice’s absence could make such a difference revealed how small the margin of conservative advantage had been. Would the term now end in deadlock? A tie is a highly unsatisfactory way to resolve a Supreme Court case: It leaves the lower court’s decision standing, but it makes no law and offers no reasoning.

The Court did deadlock in some cases. A 4  –  4 tie left standing a trial-court injunction blocking President Obama’s immigration initiative, denying relief to several million undocumented immigrants without even offering a reason. An earlier 4  –  4 tie, by contrast, saved public-union dues from a likely defeat. But for the most part, the Court avoided ties. For example, in a case asking whether Catholic nonprofits could invoke religious objections in refusing to provide insurance coverage under the ACA for their employees’ birth control, the Court sidestepped a deadlock by sending the case back to the lower courts to see if the matter could be settled.

In the term’s two most closely watched cases, however, the Court not only did not tie, but surprised virtually all of the experts. Both times, it was Justice Anthony Kennedy who delivered the surprise. In Fisher v. University of Texas, he sided with his liberal colleagues Ruth Bader Ginsburg, Stephen Breyer, and Sonia Sotomayor to uphold an affirmative-action plan (Justice Elena Kagan was recused, so only seven justices heard the appeal). It’s only the second time in the Court’s history that it has upheld a university affirmative-action plan, and it’s also the first time that Kennedy has voted in favor of any race-based government action.

Kennedy and his fellow conservatives had previously adhered to a formalistic theory of equal protection that requires “color-blindness” and treats as equally suspect the consideration of race to benefit or to harm members of minority groups. But in Fisher, Kennedy ruled that race could be considered to increase the admission of disadvantaged minorities. While the other conservative justices objected that Texas’s goal of diversity was too open-ended, Kennedy recognized that diversity’s many educational benefits cannot be reduced to precise numbers. He concluded that using affirmative action to increase diversity could survive strict judicial scrutiny if the university found that race-neutral alternatives were insufficient, and if each applicant’s file was reviewed holistically, with race playing only a modest role. Texas had achieved some racial diversity through a race-neutral plan that offered automatic admission to any Texas student in the top 10 percent of his or her high-school class, but Kennedy agreed with the university that class rank alone doesn’t allow a school to capture all of the benefits of true diversity.

As a result, affirmative action survives. The Court approved an affirmative-action plan only once before, in 2003, although it also warned in that decision that the practice should end in 25 years; significantly, Fisher contained no such warnings. As the racial protests on college campuses across the nation in the past year attest, the modest leg-up that African Americans and Hispanics receive in admissions to many schools isn’t nearly enough to repair the wounds that centuries of discrimination have inflicted, or to offset the prejudices that still impair the judgment of us all. But the country would be even more unjust without it.

On the term’s last day, the Court delivered another surprise: Whole Woman’s Health v. Hellerstedt, a 5  –  3 decision striking down restrictions on the provision of abortion in Texas. At issue were rules requiring clinic doctors to have “admitting privileges” at hospitals nearby, and compelling the clinics to meet the costly standards applicable to “ambulatory surgical centers,” even though most abortions don’t require surgery and only a minuscule percentage ever lead to hospitalization (and most of those arise after the woman has returned home, rendering irrelevant the heightened requirements imposed on clinics). The rules had forced half of the clinics in Texas to close, making it extremely difficult for women in many parts of the state to get an abortion.

Once again, Justice Kennedy cast the decisive vote. Had he sided with his conservative colleagues, the Court would have split 4  –  4, leaving standing the decision below that had upheld Texas’s restrictions. Only once before had Kennedy voted to strike down an abortion restriction—in Planned Parenthood v. Casey (1992), when he also parted company with his fellow conservatives and voted to reaffirm Roe v. Wade, notwithstanding his own earlier criticisms of Roe. Since then, however, the Court had rarely applied the “undue burden” standard announced in Casey, and in its two principal cases, both involving prohibitions on so-called partial-birth abortions, Kennedy had voted to uphold the restrictions, even though they protected neither maternal health nor the potential life of the fetus.

In Whole Woman’s Health, the Court concluded that Texas’s rules imposed an “undue burden” on the right to choose, because they did virtually nothing to advance women’s health and created substantial obstacles to abortion. As the Court noted, abortions are 14 times safer than childbirth and 10 times safer than colonoscopies, yet the heightened requirements imposed on abortion didn’t apply to these more dangerous procedures. Ever since the Casey decision acknowledged that states could regulate abortion in the name of women’s health throughout the pregnancy, abortion opponents have been using the mantle of maternal health to enact laws whose real purpose is to reduce access to abortion. In Whole Woman’s Health, for the first time, the Court called the states on this tactic. The decision is likely to invalidate similar restrictions in many other states.

Thus, a term that began by courting disaster ended by reaffirming two of the most important yet controversial practices in the United States: affirmative action and abortion. The fact that a single justice’s demise, and another justice’s willingness to break ranks with his conservative colleagues, had such dramatic consequences for the constitutional law that governs us all underscores how critical it is that the next justice not be named by Donald Trump. If readers of this magazine still harbor any doubts about the importance of vigorously supporting Hillary Clinton, this Supreme Court term should end them.