The battle over the nation’s health care law shifted from the courtroom to the ballot box Thursday, with President Obama praising the Supreme Court’s decision as a landmark that will help all Americans, and Mitt Romney, his presumed opponent, pledging to make repeal his first priority as president.

“The highest court in the land has now spoken. We will continue to implement this law. And we’ll work together to improve on it where we can,” Obama said in brief remarks at the White House.

For Democrats, the ruling is vindication for a complicated, contentious law that the party has wanted to pass for generations. “It allows Obama to say, ‘I’m fighting for you. Whether or not it’s popular, I’m working hard to do the right thing. Reelect me,’ ” said Mary Anne Marsh, a Democratic strategist from Massachusetts.

While the court’s decision was a victory for the White House, Republicans saw a political opportunity in the court’s finding that the law’s penalty for failing to buy insurance is a tax. That makes is possible to link Obama to a new tax.

“While it’s terrible news from a policy perspective, from a political perspective it’s a gift,” said Henry Barbour, a Republican National Committee member from Mississippi and a Romney supporter. “It’s going to energize conservatives and motivate them even more to work hard to stop what is just a grand overreach of the federal government.”

It is not clear, however, whether such a short-term infusion of energy for the parties’ bases will change many minds in the political middle four months from now if the economy continues to sputter.

“It’s a long time between now and November. I’m unsure that it changes the overall dynamics of the election,” said Dante Scala, a political science professor at the University of New Hampshire.

Marsh agreed that health care is a secondary issue for most voters. “It may be a part of what people consider, but it’s not the thing,” the strategist said. “In terms of drawing contrasts between Obama and Romney, this is one more.”

Nonetheless, conservatives immediately started laying the groundwork to persuade millions of voters to join them on Election Day in a political assault on the measure. They will seek to replicate their successes in 2010, when anger over how Congress pushed through the health care legislation fueled Tea Party fervor and swept Republicans into control of the House. Freedom Works, a Tea Party-affiliated group, is planning a gathering this weekend in Ohio, the state that serves as a linchpin to Romney’s strategy to win the presidency and to Republicans’ efforts to win back the Senate by beating Democrat incumbent Sherrod Brown there.

The House is planning next week to vote on a full repeal of the law, a largely symbolic move since it will not survive in the Democratic-controlled Senate but also one that will give congressional candidates a talking point on the campaign trail.

Polls in several swing states show a divided electorate. Slight majorities — 52 percent in Ohio and 53 percent in Florida — said they believe Congress should repeal the law, according to a Quinnipiac University poll released in May. Strategists say the court’s ruling and the subsequent political buzz should give at least a short-term boost to the law’s popularity.

“While it’s terrible news from a policy perspective, from a political perspective it’s a gift.”

Henry Barbour, Mitt Romney supporter

Romney’s campaign said the ruling was a boon to its fund-raising. By late afternoon Thursday, his campaign reported raising more than $2.5 million from 24,000 donors and sent out an appeal that said, “The stakes couldn’t be higher.”

Republicans are expected to seize on the tax penalty that the law applies to people who fail to obtain insurance coverage.

Democrats and the president insisted for months that the law would not raise taxes for Americans. The distinction by the court — and the use of the word “tax” to describe that penalty — now allows Republicans to weave it into their narrative of Democrats as tax-addicted lawmakers intent on expanding a bloated bureaucracy.

Yet Romney faces significant challenges in using that line of attack. As governor, he passed a law in Massachusetts that included a similar penalty levied on residents and businesses who did not obtain health insurance. Romney called it a “fee” or an “assessment,” and contends that he never raised taxes on Massachusetts.

Romney’s health care law also included an individual mandate — the requirement that all people must get insurance coverage — which was the heart of the legal challenge.

“With regards to the individual mandate, the individual responsibility program that I proposed, I was very pleased that the compromise between the two houses includes the personal responsibility mandate,” Romney said in a 2006 news conference clip that Democrats unearthed and gleefully sent around on Thursday.

The decisive vote, written by Chief Justice John Roberts, carries irony for Romney. On his campaign website, Romney pledges to “nominate judges in the mold of Chief Justice Roberts.”

Romney had been preparing his lines of attack, for whichever way the court ruled. At a campaign stop this week, he argued that a Supreme Court decision against health care would show the president had wasted three years in office.

If the court had struck down the law, “it would have played into the Romney narrative of a failed presidency,” said Jeffrey Berry, a political science professor at Tufts University.

Instead, Berry said, “it’s a decisive victory for President Obama. It evokes strong leadership, bold thinking, and reminds people that he stuck with this policy even when it was unpopular.”

Obama acknowledged the political impact of the decision, but argued in his remarks that political advantage is less important than the benefits of the law. “What we won’t do — what the country can’t afford to do — is re-fight the political battles of two years ago, or go back to the way things were,” Obama said.

Romney, responding to the court’s decision, assailed several aspects of the law, saying it would hamper businesses, add to the federal deficit, and magnify the government’s role in private health-care decisions.

“You can choose whether you want to have a larger and larger government, more and more intrusive in your life, separating you and your doctor,” said Romney, airing what is expected to be a campaign theme.

“What we do know is that for quite a while the Affordable Care Act has been a legal issue,” said Douglas Holtz-Eakin, an economist and former adviser to John McCain. “This returns it from a legal dispute to a first-rate political and policy dispute.”

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.

Thanks & Welcome to Globe.com

You now have unlimited access for the next two weeks.

BostonGlobe.com complimentary digital access has been provided to you, without a subscription, for free starting today and ending in 14 days. After the free trial period, your free BostonGlobe.com digital access will stop immediately unless you sign up for BostonGlobe.com digital subscription. Current print and digital subscribers are not eligible for the free trial.