Speaking at the White House, President Obama declared the Supreme Court ruling on health-care subsidies a win but said there is still work to be done. Here are key moments from his reaction to the ruling. (AP)

For President Obama, the threats to his health-care law have spanned the 6 1/2 -year arc of his presidency and come from virtually every direction: the Congress, the courts and the administration itself in the form of an initially faulty Web site.

“There’ve been successes and setbacks,” Obama said Thursday in the Rose Garden. Then, with a deadpan look toward Vice President Biden, he added: “The setbacks I remember clearly.”

But this was a cheerful moment to remember — an inflection point, as White House aides like to say, that brought an emerging domestic legacy into sharper focus.

The Supreme Court, in a 6-3 decision, upheld a key provision in the Affordable Care Act that ended the last major challenge to the law and cemented his signature legislative achievement — one that, the president noted, has eluded generations of White House predecessors.

Obama ticked off a series of statistics that he said, taken together, show “this law is working exactly as it’s supposed to.” But beyond the immediate accounting, the president looked to history, to the great milestones of American liberalism — Social Security and Medicare — and placed his achievement firmly among them.

The Supreme Court upheld a key provision of the Affordable Care Act. Here's what it means for millions of Americans. (The Washington Post)

“This generation of Americans chose to finish the job — to turn the page on a past when our citizens could be denied coverage just for being sick,” he said. “We chose to write a new chapter, where in a new economy, Americans are free to change their jobs or start a business, chase a new idea, raise a family — free from fear.”

Inside the West Wing, the legal victory provided a jolt of enthusiasm that Obama’s domestic achievements are accumulating just as his governing record is being scrutinized in the crucible of an election season to pick his successor.

Not long after the court ruling, lawmakers on Capitol Hill approved the final piece of a trade package that sends Obama’s top second-term legislative priority to his desk as he closes in on an ambitious Pacific Rim trade accord that the administration says will create good-paying jobs at home.

Though very different pieces of policy, the health-care and trade initiatives are tied together by the president’s “laserlike focus on expanding economic opportunity for middle-class families,” White House press secretary Josh Earnest said. Obama has cast his policies as a bridge for ordinary Americans to reach a more secure economic footing and to guide them through a rapidly changing, increasingly global economy.

“It’s very important to remember that he was coming in in the middle of the worst recession in 80 years and prevented it from becoming a Great Depression,” U.S. Trade Representative Michael B. Froman said Thursday. “He made difficult, politically unpopular decisions to get things done, and it worked.”

For the president and his advisers, there was a palpable sense of vindication, even triumph, that despite the steady carping by Beltway political rivals and reporters about Obama’s aloof leadership style and his inability to work with Congress, he was proving them wrong.

Earnest, a longtime Obama aide who knocked on doors in Iowa for him in 2008, recalled the unflappable presidential candidate who drew the moniker “no drama Obama.” The president has always focused on the long game, Earnest said, eschewing the petty, day-to-day combat that defines Washington politics.

Upholding affordable health care

Though that approach has been viewed by Obama’s critics as a disinterest in governing, Earnest called it vital to managing the White House.

“If the president spent a lot of time reading the obituaries on the trade legislation or worried about all the columns related to the impending death of the Affordable Care Act, we would not have made as much progress as we did,” he said.

Neera Tanden, president of the liberal Center for American Progress, scoffed as she recalled the many times rivals predicted that one setback or another would be “Obama’s Katrina” — a reference to George W. Bush’s botched response to the 2005 hurricane that flooded New Orleans and helped cripple his presidency.

“It’s literally everyone’s favorite thing to do to say he’s a lame duck,” Tanden said of Obama. “He still has a lot to accomplish.”

The relief at the White House was made more acute by the backdrop of Obama’s frank admission last week — after the shooting deaths of nine black parishioners at a Charleston, S.C., church by a white gunman — that he has been unable to make significant progress in two other areas that have defined his presidency: guns and race.

Obama and Biden walked into the Rose Garden on Thursday exactly one week after they had appeared together in the White House briefing room where the president delivered his first angry public remarks on the massacre. On Friday, Obama will deliver a eulogy at a memorial service for the victims.

Even while acknowledging that the nation has not fully reckoned with its racist history, Obama has urged critics to examine his policies with a broader lens, arguing that the economic stimulus plan and health-care laws passed early in his first term have benefited Americans of all races.

On Thursday, the administration scored another legal victory when the Supreme Court upheld the federal government’s broad use of the 1968 Fair Housing Act to combat housing discrimination and racial segregation.

But it was the health-care decision that elicited cheers from staff members loud enough to be heard in the halls of the White House. The ruling affirmed Obama’s conviction that, in his words, affordable health care is “not a privilege for a few but a right for all.”

Jim Messina, who served as White House deputy chief of staff when the president was working to pass the Affordable Care Act, recalled that on five separate occasions he and then-chief of staff Rahm Emanuel informed Obama that the measure was dead on Capitol Hill.

“All five times he said, ‘Well, fix it,’ ” Messina said. “He rolled all of his political dice on this.”

Aides hedged that bet only slightly Thursday. Just in case the court ruled against the administration, Obama’s chief speechwriter, Cody Keenan, had prepared an alternate set of remarks for the president.

After his Rose Garden appearance, aides said, Obama returned the unused speech with a personal inscription: “Didn’t need this one, brother!’ ”

Juliet Eilperin contributed to this report.