Republicans seized on Ms. Sebelius’s departure to heap even more criticism on the law she helped pass and carry out. “No matter who is in charge of H.H.S., Obamacare will continue to be a disaster,” said Reince Priebus, the chairman of the Republican National Committee. Senator Mitch McConnell of Kentucky, the Republican leader, said her resignation was “cold comfort to the millions of Americans who were deceived about what it would mean for them and their families” under the health care law.

The resignation is a low point in what had been a remarkable career for Ms. Sebelius, who as governor of Kansas was named by Time magazine as one of the five best governors in the country and was even mentioned as a possible running mate for Mr. Obama in 2008. The two had bonded when Ms. Sebelius endorsed his presidential bid early in 2008, becoming one of the highest-profile Democratic women to back him over Hillary Rodham Clinton, and helping him deliver a big win in the Kansas caucus.

White House officials were quick to point out the many successes during Ms. Sebelius’s tenure: the end to pre-existing conditions as a bar to insurance, the ability for young people to stay on their parents’ insurance, and the reduction in the growth of health care costs. In addition, Ms. Sebelius helped push through mental health parity in insurance plans and worked with the Department of Education to promote early childhood education.

Ms. Sebelius said in an interview on Thursday that she had always known that she would not “be here to turn out the lights in 2017.”

“My balance has always been, when do you make that decision?” she added.

The president had been under pressure for months to fire Ms. Sebelius. But he had resisted, in part because he did not want the Department of Health and Human Services to undergo more upheaval amid all the problems plaguing HealthCare.gov, and in part because of his general reluctance to publicly rebuke top officials.

In November, Mr. Obama defended the secretary, saying in an interview with NBC News that she “doesn’t write code; yeah, she wasn’t our I.T. person.” As recently as last week, Jay Carney, the White House press secretary, rejected any suggestion that Ms. Sebelius would be fired.

On Thursday, Mr. McDonough praised Ms. Sebelius as “a fierce advocate,” and said she had been “tenacious in her belief” in the president’s health care law. “She’s fearless in her defense of this idea at the heart of the Affordable Care Act,” he said. “The president has commented to me countless times how much he admires that.”