The Supreme Court wrapped up its term last week after landmark decisions protecting the right to have a gun and the right of corporations to spend freely on elections. But the year’s most important moment may have come on the January evening when the justices gathered at the Capitol for President Obama’s State of the Union address.

They had no warning about what was coming.

Obama and his advisors had weighed how to respond to the court’s ruling the week before, which gave corporations the same free-spending rights as ordinary Americans. They saw the ruling as a rash, radical move to tilt the political system toward big business as they coped with the fallout from the Wall Street collapse.

Some advisors counseled caution, but the president opted to criticize the conservative justices in the uncomfortable spotlight of national television as Senate Democrats roared their approval.

Chief Justice John G. Roberts Jr. is still angered by what he saw as a highly partisan insult to the independent judiciary. The incident put a public spotlight on the deep divide between the Obama White House and the Roberts court, one that could have a profound effect in the years ahead.

The president and congressional Democrats have embarked on an ambitious drive to regulate corporations, banks, health insurers and the energy industry. But the high court, with Roberts increasingly in control, will have the final word on those regulatory laws.

Many legal experts foresee a clash between Obama’s progressive agenda and the conservative court.

“Presidents with active agendas for change almost always encounter resistance in the courts,” said Stanford University law professor Michael W. McConnell, a former federal appellate court judge. “It happened to [ Franklin D.] Roosevelt and it happened to Reagan. It will likely happen to Obama too.”

Already, the healthcare overhaul law, Obama’s signal achievement, is under attack in the courts. Republican attorneys general from 20 states have sued, insisting the law and its mandate to buy health insurance exceed Congress’ power and trample on states’ rights.

Two weeks ago, a federal judge in New Orleans ruled Obama had overstepped his authority by ordering a six-month moratorium on deep-water drilling in the Gulf of Mexico.

On another front, the administration says it will soon go to court in Phoenix seeking to block Arizona’s controversial immigration law, which is due to take effect July 29. Republican Gov. Jan Brewer said Arizona would go to the Supreme Court, if necessary, to preserve the law.

As chief justice, Roberts has steered the court on a conservative course, one that often has tilted toward business. For example, the justices have made it much harder for investors or pension funds to sue companies for stock fraud.

Two years ago, the court declared for the first time that the gun rights of individuals were protected by the Constitution. This year, the justices made clear this was a “fundamental” right that extended to cities and states as well as federal jurisdictions.

Since the arrival in 2006 of Justice Samuel A. Alito Jr., Roberts has had a five-member majority skeptical of campaign funding restrictions. At first, he moved cautiously. Roberts spoke for the majority in 2007 in saying that a preelection broadcast ad sponsored by a nonprofit corporation was protected as free speech even though it criticized a candidate for office.

Last year, the court had before it another seemingly minor challenge to election laws by a group that wanted permission to sell a DVD that slammed Hillary Rodham Clinton when she was running for president in 2008. This time, however, Roberts decided on a much bolder move.

The 5-4 ruling in the Citizens United case struck down all limits on direct election spending — for giant, profit-making corporations as well as small nonprofit groups. For more than 60 years, Congress and many states had barred corporate and union spending to sway elections. The court’s opinion dismissed all such laws as unconstitutional censorship.

The decision came as a “real shock to the administration and to the Democrats in Congress,” said Simon Lazarus, counsel for the National Senior Citizens Law Center. “It’s also caused a sea change in their thinking about the court. Before, it was all about the ‘culture wars’ issues, like abortion, prayer and gay rights. Afterward, they saw this new activist thrust among the conservatives as a direct threat to their legislative agenda.”

The change was on full display in last week’s Senate hearing on Supreme Court nominee Elena Kagan. Democrats accused the high court of judicial activism in favor of corporations — “particularly by the five Republican appointees who have steered so hard to the right,” said Sen. Sheldon Whitehouse (D-R.I.).

Republicans in the hearing targeted Obama’s “tremendous expansion” of the government and argued for the court to aggressively restrain Congress and the White House. “The Supreme Court … ought to go for freedom, not more government,” said Sen. Tom Coburn (R-Okla.).

Obama chose Kagan for the court believing she could bridge the gap with some of its conservatives. Her mission is to help uphold the laws that Obama and Democrats are pushing through Congress.

During her hearing, Kagan found herself in the odd spot of defending judicial restraint before senators who usually worry aloud about sending a “judicial activist” to the court.

“Can you name for me any economic activity that the federal government cannot regulate under the commerce clause?” asked Sen. John Cornyn (R- Texas).

“I wouldn’t try to,” Kagan replied, emphasizing that the court has long said lawmakers have broad powers to regulate economic activity.

The high court, however, will decide whether making Americans buy health insurance amounts to economic activity.

It may be another year or two before a true challenge to the Obama agenda reaches the Supreme Court.

McConnell, the law professor, said the administration’s broad set of regulatory moves made a clash almost inevitable. “It does not mean the courts are being ‘political,’ ” he said. “It is the way the institutions are designed, to create checks and balances.”

david.savage@latimes.com