Dr. Joshua Sharfstein, Maryland’s health secretary, seated next to Gov. Martin O’Malley, and Carolyn Quattrocki, the interim director of the state’s health care exchange, in March 2014. (Brian Witte/AP)

Maryland’s top health official, Joshua M. Sharfstein, announced Wednesday that he will leave at the end of Gov. Martin O’Malley’s term in January to become an associate dean at the Johns Hopkins Bloomberg School of Public Health.

In nearly four years as secretary of the Department of Health and Mental Hygiene, Sharfstein has become one of O’Malley’s most trusted and visible Cabinet members while building a national reputation as an expert in public-health policy.

He is widely liked by many legislators for his ability to break down complicated health-care issues without becoming impatient or flustered. But Sharfstein became a lightning rod for criticism late last year after the disastrous debut of Maryland’s glitch-plagued online health-insurance exchange.

Sharfstein, a pediatrician who studied at Harvard, approached his government position not only as an administrator, but also as a health-policy wonk intent on lowering the number of preventable hospitalizations, reducing the number of infants who die, cutting health-care costs and helping more Marylanders live healthier lives.

The position at Hopkins, he said in a lengthy e-mail to employees Wednesday morning, “will allow me to stay involved in my city of Baltimore and my state of Maryland, while engaging with national and global challenges and helping to train a new generation of public health leaders.”

Vincent DeMarco, an activist and the president of the Maryland Citizens’ Health Initiative, said that Sharfstein has been “a really great asset for Maryland.”

Sharfstein’s public-policy background was no match, however, for the serious technology problems that plagued the state’s much-hyped insurance Web site, a major component of its implementation of the Affordable Care Act. The site crashed on its first day, struggled through a six-month enrollment period and is now being rebuilt.

“The IT problems of the Maryland Health Benefit Exchange last year are certainly not going to make my highlight reel,” Sharfstein said in his e-mail. “I do remember, however, the moment when Governor Martin O’Malley pulled me aside and told me that what mattered most was rising to the challenge.”

The dysfunctional site has also been a political liability for O’Malley, who is contemplating a run for president in 2016, and Lt. Gov. Anthony G. Brown, the Democratic nominee to replace O’Malley as governor.

Sharfstein became the face of the exchange, directly fielding calls from frustrated insurance carriers, lawmakers, reporters and others. He spent hours testifying before panels of local and federal lawmakers about what went wrong and why. When asked once whether he had grown tired of the grilling, Sharfstein responded that he enjoyed doing it.

And while O’Malley and Brown at first avoided issuing direct apologies for the debacle, Sharfstein did so repeatedly and profusely.

Larry Hogan, the Republican nominee for governor, said in a statement Wednesday that Sharfstein should resign immediately because of the problems with the exchange.

“Saying he plans to resign in January is hardly newsworthy,” Hogan said. “The Hogan-[Boyd] Rutherford administration would never allow this level of incompetence in one of the state’s most important agencies and would have demanded his immediate resignation in January anyway.”

Sharfstein said Wednesday that the exchange’s problems aren’t why he is leaving.

He listed among his accomplishments modernizing how Maryland hospitals set their rates, using data to tackle public-health problems, fighting drug and alcohol abuse and promoting domestic-violence screenings.

Sharfstein grew up in Maryland and graduated from Harvard Medical School. He was Baltimore’s health commissioner from 2005 to 2009, then principal deputy commissioner of the U.S. Food and Drug Administration. He returned to Maryland in January 2011 to become health secretary.

“It’s a really great job at a really important moment in time,” Sharfstein said in an interview when he was hired.

As Sharfstein announced his next job, O’Malley said in a statement: “As a Marylander, I’m thrilled that he’s going to Johns Hopkins.”

Sharfstein will become a full-time faculty member and the associate dean for public-health practice and training. He will replace Thomas Burke, who has held the position since 2008 and has been nominated by President Obama to lead the Environmental Protection Agency’s Office of Research and Development.

“We already know Josh from his lectures at our school, his mentorship of our students and our productive collaborations, and we look forward to his full-time presence and impact at the school,” said Michael J. Klag, dean of the school.

Also in his e-mail, Sharfstein told employees that he will remain “fully engaged in the tasks at hand” until January. His to-do list includes continuing to battle a spike in heroin overdoses and rebuild the insurance Web site.

“As we work together on these and other critical projects,” Sharfstein wrote, “there is no reason for goodbyes — just the opportunity to be sure our paths will cross again.”