Milley's tenure included the killing of Islamic State head Abu Bakr al Baghdadi in 2019 and providing military assistance to Ukraine's defense against the invasion by Russia in February 2022.

But it also included the chaotic withdrawal from Afghanistan two years ago and a rocky relationship with former President Donald Trump.

Calling Milley "unflinching in the face of danger," Biden said he "once ran across a bridge booby-trapped with mines to stop two battle tanks evacuating wounded troops from driving across it."

"Mark, your partnership has been invaluable to me," Biden said.

In a ceremony at Joint Base-Myer Henderson Hall near Washington, with marching bands and a red-coated fife-and-drum corps, Milley handed over command to Air Force chief General Charles Q. Brown.

Brown is only the second Black officer to become chair of the Joint Chiefs of Staff, after Colin Powell two decades ago.

Biden said Milley served in war zones as part of his long military service and had a "chest full of medals to show for it."

In his remarks, Defense Secretary Lloyd Austin recalled a time during the Iraq war when he and Milley were serving in Baghdad and their vehicle was damaged when it was hit by an improvised explosive device while en route to a hospital to see a wounded soldier.

"'Has this happened to you before?'" Austin said he asked Milley. "And he said, oh yeah, I've been blown up about five times now.'"

ROCKY RELATIONSHIP WITH TRUMP

Milley took the reins in 2019 after being nominated by Trump, but soon found himself having to balance the need to maintain his relationship with him without appearing to be political.

In 2020, he publicly apologized for joining Trump as he walked from the White House to a nearby church for a photo opportunity after authorities cleared the way of protesters using tear gas and rubber bullets.

Milley said on Wednesday he would take measures to protect his family after Trump suggested he had colluded with China in an act he said would have once warranted death.

Brown is a self-described introvert whose public persona contrasts sharply with the outgoing Milley, a loquacious Boston native.

Brown told the audience that his goal will be to deter aggression and "fight when called upon." He said the U.S. military "must focus on modernizing" with new concepts and approaches.

The promotion of Brown, a former fighter pilot with experience in the Pacific, meant Black Americans will hold the top two positions at the Pentagon for the first time - a major milestone for an institution that is diverse in its lower ranks but largely white and male at the top.

Biden appointed Austin to become the first Black U.S. secretary of defense, the top civilian position at the Pentagon.

(Reporting by Phil Stewart, Idrees Ali, Nandita Bose and Steve Holland; Editing by Lisa Shumaker, Don Durfee and Grant McCool)

By Phil Stewart and Nandita Bose