President Trump mounted a public attack unusual even for him over the Labor Day weekend, accusing his military leadership of advocating war “so that all of those wonderful companies that make the bombs and make the planes and make everything else stay happy.”Even for a president who has never hesitated to contradict himself for political advantage, it was a remarkable shift. His questioning the patriotism and judgment of America’s military leaders, even accusing them of pursuing global conflicts to profit the military-industrial complex, marked an election-year shift in which he has turned against two of the remaining institutions he spent most of first term embracing as pillars of his “America First” policy.It was Mr. Trump, from the earliest days of his transition, who talked reverentially about his “great generals,” telling two interviewers that he surrounded himself with them because they conveyed the sense of toughness he wanted to mark America’s global role.Nearly four years later, all of these generals have been banished from his inner circle.Mr. Trump himself has consistently championed American arms sales, forgiving Saudi Arabia for the killing of the dissident journalist Jamal Khashoggi and the high civilian death toll from the Saudi-led bombing campaign in Yemen — justifying it because the country buys billions of dollars annually in American weapons.“I don’t like the concept of stopping an investment of $110 billion into the United States,” Mr. Trump said just two weeks after Mr. Khashoggi, a Virginia resident, was killed by a Saudi hit squad. Mr. Trump’s defense secretary, Mark T. Esper, comes from Raytheon, a corporation at the heart of the military-industrial community. And Mr. Esper’s predecessor as acting defense secretary came from Boeing, and Mr. Trump’s Army secretary was at Lockheed Martin.Mr. Esper and the chairman of the Joint Chiefs of Staff, Gen. Mark A. Milley, responded to Mr. Trump’s tweets and comments during a furious round of phone calls to the White House chief of staff, Mark Meadows, according to administration officials.The Pentagon’s senior civilian and military leaders were particularly incensed by comments the president made on Monday at the White House, when he said “the top people in the Pentagon” wanted to “fight wars so all of those wonderful companies that make the bombs and make the planes and make everything else stay happy,” according to these officials.These officials described the calls on condition of anonymity owing to the sensitive nature of conversations with the president. Mr. Trump has harshly criticized the senior officer corps before, but in private.On Tuesday, Mr. Meadows began a cleanup effort with White House reporters and on Fox News.“Those comments are not directed specifically at them as much as it is what we all know happens in Washington, D.C.,” Mr. Meadows told reporters. He left unclear which “top people” the president was referring to if not the most senior civilian and military leaders.It was the second time in three months that Mr. Trump found himself at odds with General Milley and Mr. Esper: Both joined the president on his highly political walk across Lafayette Square during protests adjacent to the White House, and General Milley later said he should not have been there. Both opposed Mr. Trump’s demand that the Insurrection Act be invoked to deploy active-duty military troops against protesters.In interviews, both former and current Defense Department and administration officials said Mr. Trump was lashing out in large part because he was angry over an article in The Atlantic that said he disparaged American troops who were killed or wounded in war, and because he was frustrated that the military would not serve him — and solely him — as he would like.As one of these officials noted, Mr. Trump’s critique of the military-industrial complex was not an effort to embrace a warning that President Dwight D. Eisenhower issued in his famed 1961 farewell address — an apolitical moment, since Eisenhower was leaving office.Mr. Trump was a teenager when Eisenhower delivered that stinging critique. But he made no reference to it in his remarks.Instead, one former senior defense official said, Mr. Trump appeared angry at the Republican national security officials who last month publicly declared that he was a danger to the Constitution, and especially at military contractors who were not donating more to his strapped campaign or, in his view, sufficiently grateful for how he has defended their sales. Mr. Trump never considered limiting sales to Saudi Arabia even after the Saudi crown prince, Mohammed bin Salman, was implicated in international investigations of the Khashoggi killing.“I tell you what I don’t want to do,” he said on “60 Minutes” in October 2018, pushing back on pressure to suspend or limit sales. “Boeing, Lockheed, Raytheon, all these com — I don’t want to hurt jobs. I don’t want to lose an order like that. There are other ways,” he said, to punish the Saudis — though there has been no punishment.In recent months, the president has continued sales to both the Kingdom and the United Arab Emirates despite the thousands of civilians killed by their coalition in Yemen. And he has proposed new sales to the Emirates, including F-35 stealth fighters made by Lockheed Martin and Reaper drones made by General Atomics.His problem with the Pentagon leadership is more complex.After embracing retired Gen. Jim Mattis as his first defense secretary — he delighted in calling him “Mad Dog,” a nickname Mr. Mattis despised — the two men split on a variety of issues, including Mr. Trump’s pre-emptory decision to leave Syria. Mr. Trump mocked the briefing style of Lt. Gen. H.R. McMaster, his second national security adviser, and last week, reeling from accusations in the Atlantic article, he lashed out at his former chief of staff, retired Gen. John F. Kelly.Mr. Trump was said to have been especially angered at the pushback on using the Insurrection Act, and he fumed when he thought the Pentagon was resisting giving him the kind of military parade he wanted after witnessing one in France. It took a huge lift at the White House to create a Space Force, which many in the Pentagon thought unnecessary. His campaign quickly began selling Space Force paraphernalia.So it was no surprise that Mr. Trump’s comments on Monday prompted sharp criticism from senior military officers still seething over the reports of the president’s disparaging comments about American war dead, and other veterans, including Senator John McCain, who died in 2018.Even officials who said they have become used to taunts from the president reacted angrily to Mr. Trump’s latest attack.Officers currently serving must tread carefully, trying to avoid directly referring to Mr. Trump’s remarks while still making their point. The military is avowedly apolitical, sworn to uphold the Constitution and not to represent any political party or faction.Gen. James C. McConville, the Army chief of staff, pushed back against the thought that private companies could influence decisions to take military action. He told a virtual event with the news media outlet Defense One on Tuesday that he felt strongly that “senior leaders would only recommend sending troops to combat when it’s required for national security and a last resort.”In interviews over the past two days that included a dozen current and retired generals and admirals, and other high-ranking active-duty personnel, several retired officers voiced outrage.“Trump has lost the right and authority to be commander in chief,” said Anthony C. Zinni, a retired four-star Marine general who commanded American forces in the Middle East. “His despicable comments used to describe the honorable men and women in uniform, especially those who have given the last full measure, demonstrated the lack of respect for those he is charged to lead. He must go.”General Zinni noted that when he served as a director on the board of BAE Systems, a defense contractor, he publicly opposed the Iraq war. He also served in the Bush and Trump administrations as an unpaid special mediator to help resolve disputes between the Israelis and Palestinians, Qatar and other Persian Gulf states, and in Indonesia.To assert that Pentagon brass sought to prolong endless wars in Iraq, Afghanistan and other hot spots around the globe to profit off weapons sales in those conflict zones was offensive, he said.“I have too many friends resting in Arlington to allow his disgraceful comments to stand,” General Zinni said.Several senior active-duty officers, who spoke on condition of anonymity to avoid being punished for publicly criticizing the commander in chief, said Mr. Trump’s attacks on the armed services’ leadership and his ridicule of war dead had eroded his standing in the ranks and could affect his support among military families.And with both supporters and detractors of Mr. Trump in the Pentagon’s senior echelons hardening their positions amid the uproar, many national security analysts voiced concern that the president’s remarks could divide the nation’s top officer corps at a critical time.“At this point, he’s now into the ‘throwing spaghetti against the wall’ strategy,” said Derek Chollet, a former assistant defense secretary in the Obama administration. “It’s hard to divine the logic of what he’s doing because this is the same president who triumphantly championed major arms sales as if they were nothing more than a jobs program.”At its heart, Mr. Trump’s relationship with the military and the Pentagon is one of deep misunderstanding, even four years into the job.Echoing the main allegations in the Atlantic article, two senior U.S. officials said they had personally heard Mr. Trump question why troops go to war. The officials said Mr. Trump had said several times: “Why do these guys do this? With the kind of money they make?” The implication, the officials said, was that the monetary payment to troops did not justify the potential sacrifice.Mr. Chollet, who is now executive vice president at the German Marshall Fund, said Mr. Trump simply did not understand the role of the American military.“Just as he is endlessly frustrated by a media that will not bend to his whim, he’s frustrated by a military that takes an oath to the Constitution and not to the president,” he said.