WASHINGTON — At his confirmation hearings in 2005, Chief Justice John Roberts Jr. said he saw himself as an “umpire,” and that “nobody ever went to a ball game to see the umpire.”

No doubt nobody did Thursday either, when spectators packed the U.S. Supreme Court and clogged the front steps awaiting its ruling on the health-care law, one of the more anticipated and possibly politically pivotal decisions in recent years.

Roberts turned out to be the surprise attraction, a conservative nominated by President George W. Bush who had sided with the court’s liberal wing when it announced the 5-4 outcome to uphold President Barack Obama’s key domestic achievement.

“I will remember that it’s my job to call balls and strikes and not to pitch or bat,” Roberts told his Senate inquisitors seven years ago. But in his ruling, he certainly threw a curveball few had expected.

Not only did Roberts bail out Obama, who as a senator had voted against Roberts for the court, he also snuffed out one of the Republican Party’s biggest lines of attack.

The chief justice may have had larger, more long-term concerns on his mind than this year’s presidential election.

“For him to have taken a very predictable ideological position would have meant that he wasn’t a particularly independent legal thinker, and it’s very difficult to get your place at the head of the line of justices until you’ve somehow made your own mark,” said Steven Smith, a professor of political science at Washington University in St. Louis.

“He found a way to pave the path that was somewhat unpredictable.”

Liberals praised Roberts. Jeffrey Rosen, a George Washington University law professor, called it “a dramatic vindication of the vision of bipartisanship that Chief Justice Roberts articulated at the start of his term.”

Conservatives felt a keen sense of betrayal.

“The worst part of the Bush legacy,” tweeted Ben Shapiro, a conservative commentator and talk show host.

“His reputation is forever stained in the eyes of conservatives, and there will be no rehabilitating of it,” conservative Brent Bozell told the website The Daily Caller. “He will be seen as a traitor to his philosophy.”

Roberts had previously been a federal appeals court judge, and a conservative Republican Washington insider before that, who did stints at the Justice Department, the White House and a top Washington law firm.

Roberts clerked for the late Supreme Court Justice William Rehnquist before Rehnquist moved up to chief justice. At his confirmation hearings, Roberts called Rehnquist a “mentor,” one who also had a moment when he confounded legal and political expectations.

In 2003 Rehnquist sided with the court’s liberals by ruling that states had to comply with the federal Family and Medical Leave Act, a Clinton administration accomplishment.

Lately, however, the court has come to be seen in some quarters as dancing too close to the political fires. More than three-quarters of the public thinks the justices allow their personal or political views to color their decisions, according to a recent CBS News/New York Times poll.

Laurence Tribe, a liberal professor of constitutional law at Harvard Law School who taught Roberts and Obama, said he was pleased that Roberts “saved the day,” not just on the health-care law, but also “perhaps the court, whose place as a legal institution had begun to fall into dangerous disrepute.”

The ruling, Tribe said, would be central to Roberts’ legacy.

“This is a really huge matter,” he said. “Nothing the Roberts court has done in the past ... did as much harm as this decision will have done good.”