Dr. Margaret Hamburg, the commissioner of the Food and Drug Administration, who led the agency for nearly six years through a period of rapid change in medical science, announced Thursday that she was stepping down.

Dr. Hamburg, 59, told colleagues in an email that she would depart at the end of March. She said in a telephone interview that she had never expected to stay as long as she did but had kept finding issues she wanted to shape and problems she wanted to help solve. She said she was particularly proud of her role in modernizing how the agency regulated the safety of food and drugs coming from other countries.

“Six years in this job is really a lot,” she said. “When I took over, it was often described as an agency in crisis. I’ve been able to turn that around, to really improve morale and change the culture of the agency in some important ways. I hope that I’ve really made it a stronger and better place.”

One of the longest-serving commissioners at the agency, Dr. Hamburg was nominated by President Obama and confirmed by the Senate in 2009. She had a behind-the-scenes leadership style that some criticized as not tough enough but others praised as the best way to be effective in an era of intensely partisan politics.