You can tell a lot about a person by what he or she regrets. This holds especially for Supreme Court justices, whose decisions can, with a single vote, upend individual lives and alter the course of history. Justice Lewis F. Powell Jr. said he probably made a mistake in upholding a law criminalizing gay sex; Justice Harry Blackmun was sorry he ever voted to impose the death penalty.

Justice Sandra Day O’Connor, who died on Friday at the age of 93, expressed regret publicly over one vote she cast: in the case of Republican Party of Minnesota v. White, a 2002 ruling that judicial candidates could not be prohibited from expressing their views on disputed legal and political issues. Minnesota, like many states that elect judges, had imposed such a ban in order to preserve the appearance of judicial impartiality. The court rejected the ban for violating the First Amendment. The decision was 5 to 4, with Justice O’Connor joining the majority.

The court’s ruling led to an explosion of partisan spending on judicial elections around the country and judicial candidates freely spouting their predetermined views on the very issues they would be entrusted to decide if elected.

There are many ways to remember Justice O’Connor — as the first woman on the Supreme Court, as one of the justices who saved Roe v. Wade 30 years ago, as the author of the landmark decision protecting affirmative action in 2003. As impressive as those achievements were, they have mostly been surpassed or reversed. What stands out for me is what she said and did after leaving the court.

Her response to the 2002 ruling would define most of her last years and underline her commitment to American democracy not just in the halls of justice but also on the ground. It was as if she could see what was coming as the judiciary grew ever more politicized, and she devoted much of her postcourt public life to combating that trend.

In March 2006, only weeks after she stepped down, she gave a speech calling out Republican lawmakers for attacking the judiciary. She highlighted the comment by Senator John Cornyn of Texas that deadly violence against judges might be related to their rulings.

The desire to protect judicial independence wasn’t unique to her, of course, but she pursued the issue like almost no one else. As she made clear in her concurring opinion in the 2002 ruling, she was not a fan of electing judges; having been appointed as a judge herself, to the Arizona appeals court, she thought judicial elections were a terrible idea. But once a state had decided on that method, she argued, they couldn’t prevent candidates from speaking out on the issues that voters cared about.

“I think she thought the decision would put an end to elected judges,” Margaret Marshall, who served as chief justice of the Massachusetts Supreme Judicial Court, told me. “She didn’t understand that once you’ve given people the opportunity to vote for something, whether judge or sanitation worker, you’ll never get that taken back.”

The ruling’s damage to the public’s trust in the judiciary was clear, as Justice O’Connor admitted in a talk to a conference of state judges in 2006, shortly after she retired. “That case, I confess, does give me pause,” she said.

The next year, during a lecture at Cornell Law School, she said, “I try never to look back,” but admitted that people would be shocked by how much money interest groups were spending to influence the outcomes of judicial elections. Referring to the 2002 decision, she said, “I think there are real problems as a result of that case, and I am very concerned about what it’s doing to this country to have partisan election of judges.”

She began to understand the depth of the problem, but unlike Justices Powell and Blackmun, whose confessions could be considered too little and too late, Justice O’Connor decided she would do something about it.

In her postcourt years, she devoted herself to the advocacy of judicial independence — the idea that for democracy to function, the people must believe that judges are examining each case and deciding them on the merits, not on political or other biases.

“I must have heard her talk about that more times than any other justice I can think of,” Ms. Marshall said. “That’s what she spent the rest of her life trying to instill in the American psyche, in schoolchildren and bar associations.”

Justice O’Connor’s concern about politicized courts will grow more urgent in her absence, as the danger becomes more starkly visible. In Ohio and North Carolina, state supreme courts had ruled that Republican-drawn partisan gerrymanders illegally favored Republicans. But after elections gave the courts solid conservative majorities, they let biased maps stand. These rulings could help decide control of the U.S. House of Representatives in 2024 and beyond.

The opposite scenario is playing out in Wisconsin, where the state Supreme Court’s majority recently tipped in favor of Democrats, after the most expensive judicial election in American history — over $40 million in spending.

The effect of all this big spending and partisan campaigning, as Justice O’Connor warned, is to undermine the public’s confidence in an entire branch of government. Appointing judges rather than electing them would make a difference, but it’s not a magic bullet. After all, U.S. Supreme Court justices are appointed, and yet the current crop is among the most nakedly political in history.

Through her yearslong crusade, Justice O’Connor seemed almost to be doing penance for the 2002 ruling. The willingness to admit error does not come easily to judges, but by doing so, she was practicing the very independence of mind she insisted on.