Dr. Anthony S. Fauci announced on Monday that he would step down as President Biden’s top medical adviser and director of the National Institute of Allergy and Infectious Diseases, which he has led for 38 years, in December to “pursue the next chapter” of his career.

Dr. Fauci’s 81-year-old announcement was not entirely unexpected. He’d been hinting for a while that he was thinking about retiring. In an interview Sunday evening, he stated that he would “not retire in the traditional sense,” but would instead devote himself to traveling, writing, and encouraging young people to join the government.

Mr. Biden thanked Dr. Fauci in a statement on Monday, calling him a “dedicated public servant and a steady hand with wisdom and insight.” When Mr. Biden was vice president, the two worked closely together during a global outbreak of the Zika virus.

Few scientists have had such a large and long-lasting influence on public policy. Dr. Fauci joined the National Institutes of Health in 1968, during the presidency of Lyndon B. Johnson, and was named director of its infectious disease branch in 1984, when the AIDS epidemic demanded attention.

Dr. Fauci has advised every president since Ronald Reagan, a total of seven times, and is an expert at navigating the intersection of science and politics. Among his proudest achievements, he said, was his collaboration with President George W. Bush in developing PEPFAR, a global program to combat H.I.V./AIDS that has saved an estimated 21 million lives. Mr. Bush, whose father, George Bush, referred to Dr. Fauci as a “hero” during a presidential debate in 1988, bestowed the Presidential Medal of Freedom on him in 2008.

However, Dr. Fauci, who rose to prominence when the coronavirus began to spread in 2020, was unable to avoid the Trump era’s politicization. President Donald J. Trump openly considered firing him (though that would have been difficult because Dr. Fauci is not a political appointee). Conservatives saw Dr. Fauci as a symbol of lockdowns and masks, which they opposed vehemently.

Senator Rand Paul, a Republican from Kentucky, publicly accused Dr. Fauci of lying about research his institute was funding in China, where the coronavirus emerged. Mr. Paul and other Republicans have vowed to investigate Dr. Fauci if Republicans gain control of Congress this fall, and it has been speculated that Dr. Fauci might retire to avoid that possibility.

Dr. Fauci dismissed that notion as “nonsense,” and added that he had no plans to work for the pharmaceutical industry, as some of his detractors have suggested. He said he considered leaving after Mr. Trump left the White House, but felt he couldn’t refuse Mr. Biden’s request to serve as his medical adviser in the midst of the coronavirus crisis.

Dr. Fauci has spent more than five decades as a government scientist, guiding the United States through a variety of infectious disease threats. However, prior to the coronavirus, he was best known for his work on HIV/AIDS. He was divisive at the time, as activists accused him of being responsible for the deaths of gay men by not moving quickly enough to get new treatments approved.

Caring for AIDS patients during a time when nearly all of them died had a profound impact on Dr. Fauci. In a National Geographic documentary released last year, he recalled arriving at the bedside of an AIDS patient who suddenly did not recognize him; the man had lost his vision.

Dr. Fauci’s voice cracked as he told the story. The filmmakers questioned why it was still bothering him after all these years. He took a breather to collect himself. “Post-traumatic stress disorder,” he explained, pausing once more. “That’s exactly what it is.”

During the early days of the coronavirus pandemic, Dr. Fauci became a household name. His image appeared on sweatshirts, knee socks, and mugs, and a petition to name him People magazine’s “Sexiest Man Alive” received over 28,000 signatures.

In an interview this year, Dr. Fauci was asked why he had become such a polarizing figure, and he pointed to some of Mr. Trump’s aides, who he said tried to humiliate him by insisting that everything he said was incorrect. He avoided addressing Mr. Trump directly.