Mr Milley, who steps down from the role after a four-year term, first hailed the US military as “unique among the world’s armies” during his speech.
“We don’t take an oath to a country,” he continued. “We don’t take an oath to a tribe. We don’t take an oath to a religion.”
And then he appeared to take a swing at the ex-commander-in-chief.
“We don’t take an oath to a king, or queen, or a tyrant or a dictator. And we don’t take an oath to a wannabe dictator. We don’t take an oath to an individual.
“We take an oath to the Constitution, and we take an oath to the idea that is America and we’re willing to die to protect it.”
It comes after Mr Milley confirmed he was taking “adequate safety precautions” in response to apparently threatening language used by Mr Trump in a post on his social media platform, Truth Social.
Gen Milley’s charisma and outspokenness initially endeared him to then-President Trump, who rejected his Pentagon leaders’ choice for chairman and chose Mr Milley.
But over time the pair’s relationship became fractious, culminating in a recent social media post by Mr Trump, which suggested Mr Milley be executed for treason following his communications with China.
Mr Trump wrote: “This guy turned out to be a Woke train wreck who, if the Fake News reporting is correct, was actually dealing with China to give them a heads up on the thinking of the President of the United States.
“This is an act so egregious that, in times gone by, the punishment would have been DEATH! A war between China and the United States could have been the result of this treasonous act.”
The remarks sparked outrage from other political and military officials, including retired General Barry McCaffrey and former Speaker Nancy Pelosi, who said Mr Trump should be barred from serving in public office for his comments.
After taking up the position in 2019, Mr Milley oversaw multiple crises, including the pandemic, the Ukraine war, a chaotic withdrawal from Afghanistan and the January 6, 2021, riot on Capitol Hill.
President Joe Biden was present at Mr Milley’s retirement ceremony on Friday, which took place at Joint Base-Myer Henderson Hall near Washington DC, and said the general was “unflinching in the face of danger”.
"Mark, your partnership has been invaluable to me," Biden said.
Mr Milley will hand over the position of Joint Chiefs of Staff to Air Force chief General Charles Q Brown Jr. Mr Brown is only the second Black officer to become chair of the Joint Chiefs of Staff, after Colin Powell two decades ago.