"I should not have been there," the Joint Chiefs chairman said in remarks to a National Defense University commencement ceremony.
Trump's June 1 walk through the park to pose with a Bible at a church came after authorities used pepper spray and flash bangs to clear the park and streets of largely peaceful protesters demonstrating in the aftermath of George Floyd's death in Minnesota in police custody.
Milley's statement risked the wrath of a president sensitive to anything hinting of criticism of events he has staged. It comes as Pentagon leaders' relations with the White House are still tense after a disagreement last week over Trump's threat to use federal troops to quell civil unrest triggered by Floyd's death.
Milley said his presence and the photographs compromised his commitment to a military divorced from politics.
"My presence in that moment and in that environment created a perception of the military involved in domestic politics," Milley said. "As a commissioned uniformed officer, it was a mistake that I have learned from, and I sincerely hope we all can learn from it."
After protesters were cleared from the Lafayette Square area, Trump led an entourage that included Milley and Defense Secretary Mark Esper to St. John's Episcopal Church, where he held up a Bible for photographers and then returned to the White House.
Esper had not said publicly that he erred by being with Trump at that moment. He told a news conference last week that when they left the White House he thought they were going to inspect damage in the Square and at the church and to mingle with National Guard troops in the area.
Milley's comments at the National Defense University were his first public statements about the Lafayette Square event on June 1, which the White House has hailed as a "leadership moment" for Trump akin to Winston Churchill inspecting damage from German bombs in London during World War II.
The public uproar following Floyd's death has created multiple layers of extraordinary tension between Trump and senior Pentagon officials. When Esper told reporters on June 3 that he had opposed Trump bringing active-duty troops on the streets of the nation's capital to confront protesters and potential looters, Trump castigated him in a face-to-face meeting.
Just this week, Esper and Milley let it be known through their spokesmen that they were open to a "bipartisan discussion" of whether the 10 Army bases named for Confederate Army officers should be renamed as a gesture aimed at disassociating the military from the racist legacy of the Civil War.
On Wednesday, Trump said he would never allow the names to be changed, catching some in the Pentagon by surprise.
The Marine Corps last week moved ahead with a ban on public displays of the Confederate Army battle flag on its bases, and the Navy this week said it plans a similar ban applied to its bases, ships and planes. Trump has not commented publicly on those moves, which do not require White House or congressional approval.
Milley used his commencement address, which was prerecorded and presented as a video message in line with social distancing due to the coronavirus pandemic, to raise the matter of his presence with Trump in Lafayette Square. He introduced the subject to his audience of military officers and civilian officials in the context of advice from an Army officer and combat veteran who has spent 40 years in uniform.
He said all senior military leaders must be aware that their words and actions will be closely watched.
"And I am not immune," he said, noting the photograph of him at Lafayette Square. "That sparked a national debate about the role of the military in civil society." He expressed regret at having been there and said the lesson to be taken from that moment is that all in uniform are not just soldiers but also citizens.
"We must hold dear the principle of an apolitical military that is so deeply rooted in the very essence of our republic," he said. "It takes time and work and effort, but it may be the most important thing each and every one of us does every single day."
Milley also expressed his outrage at the Floyd killing and urged military officers to recognize as a reflection of centuries of injustice toward African Americans.
"What we are seeing is the long shadow of our original sin in Jamestown 401 years ago," he said, referring to the year in which the first enslaved Africans arrived on the shores of colonial Virginia.
Milley said the military has made important progress on race issues but has much yet to do, including creating the conditions for a larger proportion of African American officers to rise to the military's senior ranks. He noted that his service, the Army, has just one African American four-star general, and mentioned that the Air Force is about to swear in the first-ever African American service chief.