The top military officer in the US has said he was wrong to accompany President Donald Trump on a walk through Lafayette Square in Washington that ended in a photo opportunity at a church.

Army General Mark Milley said his presence “created a perception of the military involved in domestic politics”.

“I should not have been there,” the Joint Chiefs chairman said in remarks to a National Defence University commencement ceremony.

READ MORE: Billy Connolly on 'pathetic' Scottish Labour and what he really thinks about independence

Mr Trump’s walk through the park on June 1 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.

Gen 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 Mr Trump’s threat to use federal troops to quell civil unrest triggered by Mr Floyd’s death.

Gen 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,” he 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, Mr Trump led an entourage that included Gen Milley and defence secretary Mark Esper to St John’s Episcopal Church, where he held up a bible for photographers and then returned to the White House.

Mr Esper had not said publicly that he erred by being with Mr 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.

Gen Milley’s comments were his first public statements about the Lafayette Square event, which the White House has hailed as a “leadership moment” for Mr Trump akin to Winston Churchill inspecting damage from German bombs in London during the Second World War.

READ MORE: Jeane Freeman launches attack on Westminster 'failure' to collaborate on pandemic fight

The public uproar following Mr Floyd’s death has created multiple layers of extraordinary tension between Mr Trump and senior Pentagon officials. When Mr Esper told reporters on June 3 that he had opposed Mr Trump bringing active-duty troops on the streets of the nation’s capital to confront protesters and potential looters, Mr Trump castigated him in a face-to-face meeting.

Just this week, Mr Esper and Gen 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, Mr Trump said he would never allow the names to be changed, catching some in the Pentagon by surprise.