It was a rare instance of a president laying out his own arguments about a Supreme Court case before the justices are set to reach their decision.
In his first public comments about the case since the justices took it up last week, Mr. Obama appeared to be framing the political argument he would make should he have to face voters this fall after a loss at the high court.
"For years, what we've heard is the biggest problem on the bench was judicial activism or the lack of judicial restraint, that an unelected group of people would somehow overturn a duly constituted and passed law," he said at a news conference. The health-care case is a good example of just that, he said. "And I'm pretty confident that this court will recognize that and not take that step."
White House officials have said they were reluctant to appear to lobby the Supreme Court, which is partly why the president didn't speak out on the case until after it was argued before the court last week.
Rather, the president's comments indicate how he might deal with the political fallout should he lose, framing the court as a potential villain that substitutes its judgment for that of elected legislators, and Americans who lose benefits of the law as victims. Mr. Obama ticked off a string of popular benefits that would disappear if the law is shot down, such as barring insurers from discriminating against people with pre-existing conditions.
Obama aides argue the election is likely to turn on the economy, but others say a negative court decision would be a severe blow to his re-election. Aggressive questions from several justices last week made it clear that the law, or at least its central tenet, could be struck down.
But Mr. Obama, a former constitutional law professor, said he was confident the high court would not take that step, partly because conservatives—who are in the majority on the court—have long argued against what some refer to as legislating from the bench. He noted that two conservative appellate judges who heard the case found the law constitutional.
Sen. Orrin Hatch (R., Utah), among the first to argue that the mandate to buy insurance was unconstitutional, responded, "It must be nice living in a fantasy world where every law you like is constitutional and every Supreme Court decision you don't is 'activist.'"
Mr. Obama said the court would take an "unprecedented, extraordinary step" if it overturns the law because it was passed by "a strong majority of a democratically elected Congress." The vote actually was close—it passed with 60 votes in the Senate, just achieving the supermajority needed to overcome a Republican filibuster, and by 219-212 in the House.
The Supreme Court sometimes overturns laws passed by Congress, as it did in 2010, when major parts of campaign-finance restrictions were nullified in the Citizens United decision. It would be more unusual for the court to strike down an entire law with hundreds of provisions over constitutional problems with just one part.
The challengers' case against the Obama law centers on its provision requiring most Americans to carry health insurance or pay a penalty. Several conservative Supreme Court justices suggested at last week's arguments that if the provision is found unconstitutional, the entire law must fall because it would be too messy for the court to untangle which provisions were connected to the insurance mandate. The Supreme Court ruling is expected by the end of June.
Conservatives have long complained that liberals turned to the courts for victories they couldn't win at the ballot box, deriding judges who overturn popularly enacted laws as "judicial activists."
In this case, the president said, it was conservatives who were betting Republican-appointed judges would nullify the legislative victory he and fellow Democrats achieved after the 2008 elections.
Challengers, including 26 states and a small-business group, argue that Congress has never required Americans to buy a product, in this case health insurance. The Obama administration says Congress properly used its authority over interstate commerce to regulate how consumers finance something they are bound to require: health care.
The two conservative appellate judges who found the law constitutional were Judge Lawrence Silberman in Washington, D.C., and Judge Jeffrey Sutton in Cincinnati. "The right to be free from federal regulation is not absolute, and yields to the imperative that Congress be free to forge national solutions to national problems," Judge Silberman wrote last November. An appellate court in Atlanta ruled against the insurance mandate, finding it "breathtaking in its expansive scope."
Democrats have been trying for more than three years to make the case for the mandate to buy insurance, and Mr. Obama tried again on Monday. He said that without the mandate, it would be impossible to require insurance companies to cover everybody, including those with pre-existing conditions, at a reasonable price.
Sean Spicer, a spokesman for the Republican National Committee, said Republicans would concede some provisions of the law were popular but argue the Democrats went too far by imposing the insurance mandate.
James Simon, a professor at New York Law School, said, "I can't think of a president anticipating a court decision as Mr. Obama has done and basically arguing in favor" of his side. Mr. Simon, the author of several books on conflicts between presidents and the court, said, "Jefferson was very angry at the Marshall Court, but he [complained] in private," as did most other presidents.
President Franklin Roosevelt "usually waited until they handed down a decision" before fulminating against the court, Mr. Simon said, such as when FDR blasted a 1935 ruling striking down portions of the National Industrial Recovery Act.
Mr. Simon said he doubted the justices "are going to be influenced one way or the other" by Mr. Obama's words.
—Jess Bravincontributed to this article.
Write to Laura Meckler at laura.meckler@wsj.com and Carol E. Lee atcarol.lee@wsj.com