For former defense secretary Jim Mattis, it was the last straw: the sight of the chairman of the Joint Chiefs of Staff, walking the streets of downtown Washington in battle-ready camouflage amid a show of brute federal force.

Smoke was still rising from Lafayette Square, where authorities had just used pepper spray and smoke canisters to disperse a group of largely peaceful protesters, when Gen. Mark A. Milley, along with Defense Secretary Mark T. Esper, joined President Trump on Monday evening as he strolled to nearby St. John’s Episcopal Church to pose for cameras with a Bible.

In Mattis’s eyes, the appearance of the two top military leaders appeared to condone an unprovoked use of force. The nonpartisan military that Mattis had served for nearly five decades was being featured as decoration for a photo op, and Mattis fumed that the president was using the leaders who replaced him at the Defense Department to further divide the nation, according to four people familiar with his thinking.

He was especially upset to see Milley — who Mattis believed had sought to curry favor with Trump when he was defense secretary — appear in his Army combat uniform at a peaceful demonstration. That jarring image highlighted the military’s involvement in a heavy-handed crackdown on civilians.

With that, the military historian and retired Marine general decided it was time to call out the damage he saw Trump doing to the country.

“The military was never set up to prop up anyone’s political agenda, and I think that really pissed him off, when he saw that,” said Carlton Kent, a retired sergeant major of the Marine Corps who advised Mattis in Iraq. “He never wanted them to be in a compromising situation.”

In a statement published by the Atlantic two days later, Mattis described himself as “angry and appalled” — and denounced the president he had served for two years.

“When I joined the military, some 50 years ago, I swore an oath to support and defend the Constitution,” Mattis wrote. “Never did I dream that troops taking that same oath would be ordered under any circumstance to violate the Constitutional rights of their fellow citizens — much less to provide a bizarre photo op for the elected commander-in-chief, with military leadership standing alongside.”

Mattis’s decision to thrust himself in the maw of the country’s fraught politics — after long hovering on the sidelines — grew out of his ongoing concern about the Defense Department’s independence, according to people who know him.

His former colleagues still serving in the military had warned him in recent months about Trump’s sway over its leadership. Some told him that Esper had been dubbed “Yesper” by some in the Pentagon because he seemed unable to say no to the president. And they said they believed Milley was effectively running the department by talking to Trump directly and bypassing the secretary, a dynamic that potentially threatened civilian control of the military.

Several Pentagon officials declined to address Mattis’s criticism on the record.

An administration official, who spoke on the condition of anonymity because of the sensitivity of the issue, defended Esper’s actions during a “fast-moving week.”

“Esper is working to keep the Department of Defense apolitical in turbulent times,” the administration official said. “That is not easy and is not without criticism — both inside and outside DoD — but in the long run it is what is best for the department, the men and women in uniform, and the nation.”

The official said Mattis never reached out to his successor to share his concerns before his statement was published.

“Not Monday. Not Tuesday. Not Wednesday,” the official said. “He should still have the office number.”

Mattis’s decision to speak out came after he had long refused to directly criticize Trump, even though the fact that he had been frustrated with the president was well known. Critics have said he should have used his standing to express his concerns sooner, noting that in his book “Call Sign Chaos,” published last year, he faulted Obama administration decisions but held back when it came to the sitting president.

In a PBS interview during his book tour, Judy Woodruff prodded Mattis on why he had not offered his assessment of Trump, noting that Americans would soon be deciding whether to give him a second term. “Are you saying you don’t think it’s your responsibility to speak up before the election?” she asked.

“That’s exactly what I’m saying,” Mattis replied, adding that he and other former defense secretaries believe “the defense of this country is a nonpartisan issue.”

Mattis had told friends that he did not want any critiques he has to interfere with the efforts of the new defense secretary and his former colleagues at the Pentagon to work with the White House.

He made his general disagreement with the president clear when he announced his resignation in December 2018 amid a disagreement with the president’s decision to withdraw troops from Syria at the Turkish president’s request. Mattis’s resignation letter signaled his disapproval of Trump’s long-standing objections to international alliances, and his dismay at the president leaving Kurdish allies unprotected in Syria.

“My views on treating allies with respect and also being clear-eyed about both malign actors and strategic competitors are strongly held and informed by over four decades of immersion in these issues,” Mattis wrote.

But while at the helm of the Pentagon, Mattis himself failed at times to shield his department from the perception that the military was furthering the president’s political objectives.

The most prominent example was Trump’s contentious deployment of active-duty troops to the southern U.S. border beginning in fall 2018, just ahead of midterm elections. Trump, citing migrant caravans heading north through Mexico, said he wanted the military to fortify the border, and at one point said that if migrants threw rocks at U.S. troops, they should “consider that a firearm.”

When pressed about the border mission, Mattis dismissed suggestions that the troops were being used for political purposes, saying, “We don’t do stunts.” He visited the border in November 2018, one month before he resigned, and defended the mission.

In another incident that angered some in the military, Trump signed an executive order for a travel ban on immigrants from several Muslim-majority countries in the Pentagon’s Hall of Heroes, a revered space meant to honor the nation’s Medal of Honor recipients. Mattis stood next to him as Trump signed the order.

Since the civil unrest that has followed the police killing of George Floyd, Trump has repeatedly raised the threat of military force to quell the protests and pushed the Pentagon to deploy troops to cities hit hard by protests.

Last weekend, after a police station in Minneapolis was burned, Trump tweeted that “THUGS” were “dishonoring the memory of George Floyd,” and said he told Minnesota Gov. Tim Walz (D) that “the Military is with him all the way.” He appeared to threaten protesters, tweeting, “When the looting starts, the shooting starts.”

On May 29, as protests spread to Washington and other cities, active-duty members of the Army were put on alert.

“Crossing State lines to incite violence is a FEDERAL CRIME!” Trump tweeted Saturday. “Liberal Governors and Mayors must get MUCH tougher or the Federal Government will step in and do what has to be done, and that includes using the unlimited power of our Military and many arrests.”

Esper and Milley, meanwhile, were advocating privately to use the National Guard — but not active-duty troops, which have rarely been called up to respond to domestic unrest.

The current secretary has repeatedly stressed his belief that the U.S. military should remain apolitical. But at least two incidents on Monday drew Mattis’s ire.

First, on a call with Trump, administration officials and governors, Esper said that the sooner that authorities could “dominate the battlespace” in their cities, the sooner things could return to normal. A recording of that call leaked to the media within hours.

Then, minutes after federal authorities rushed at demonstrators with shields and batons, Esper and Milley walked with Trump from the White House to St. John’s Episcopal Church, which had been damaged in a fire started during protests.

The White House quickly packaged the scene into a video set to triumphant music.

The following day, the Pentagon announced that it was deploying 1,600 active-duty troops to the Washington area, including infantrymen. That decision was reversed by Esper this week, halted for a day amid the tension and then continued Thursday night.

Mattis was especially irked by Milley’s presence at Lafayette Square. The two men’s relationship had soured shortly before Mattis resigned, according to people with knowledge of the episode.

At the time, Milley was serving as the Army’s top general, and he asked Mattis if he could speak with Trump to seek a new role as chief of the U.S. European Command and the supreme allied commander of Europe for NATO. After the meeting, the president chose Milley as the new chairman of the Joint Chiefs of Staff, bypassing Mattis’s recommendation of the Air Force’s top officer. Mattis believed Milley had misled him and lobbied for the job; Milley told aides that he and Trump hit it off and that Trump simply offered it.

Amid this week’s furor, some Pentagon officials have privately acknowledged that it was a mistake for Esper and Milley to appear with Trump on Monday evening after the protesters had been forcefully cleared away.

Esper’s supporters say he has attempted to right the ship when it comes to keeping politics out of the department, sending a message to U.S. troops on Tuesday night that reminded them of their role to protect the American people and highlighting on Wednesday at the Pentagon the role of the National Guard in maintaining peace in the nation.

Under fire, Esper also expressed regret for his use of the term “battlespace,” saying it was a part of the lexicon he grew up with as an Army officer. He said that when he joined Trump for the walk through Lafayette Square, he thought he was going to survey damaged buildings and meeting National Guard members, not participate in a photo op.

But for Mattis, the damage was done.

“He knew his voice would have power and he could see that nobody was stopping this danger,” one ally said.

Mattis reached out to Jeffrey Goldberg, editor of the Atlantic, which had published a piece he wrote last fall about the importance of the country’s unity. On Tuesday, Mattis began writing his statement. The next day, he shared it with Goldberg, who published it that evening with the headline “James Mattis Denounces President Trump, Describes Him as a Threat to the Constitution.”

Kent, who speaks frequently with Mattis, said he was glad to see his old battle buddy speak up. Other retired generals, including David Petraeus, have since, as well.

“You never should put them in a compromising situation in the military,” Kent said. “You should never put them in a political situation, and that’s where they are right now.”