At midnight on Sept. 30, Gen. Mark A. Milley’s turbulent term as chairman of the Joint Chiefs of Staff will end.He is the last senior official whose tenure spanned both the Trump and the Biden administrations, a time that included just about every kind of crisis.Insurrection. Pandemic. The chaotic ending of the war in Afghanistan. Russia’s invasion of Ukraine. Shoot-downs of unidentified flying objects.There was that time his boss wanted to deploy American troops on the streets against American citizens. The day U.S. intelligence picked up talk among Russian generals about using a tactical nuclear weapon in Ukraine. And a Republican senator’s blockade of military promotions that delayed his successor’s confirmation.As the senior military adviser to two presidents, General Milley demonstrated loyalty, until he deemed it no longer in the country’s interest, and was often praised for his leadership. But he also made very public mistakes, including an especially egregious one for which he would later apologize.In the end, his chairmanship was shaped by a straightforward loquaciousness, a commander in chief who specialized in chaos and a chain of fast-moving events around the world.“No one was asked to do as difficult a series of things as he had to do,” said Peter Feaver, a Duke University professor who has studied the armed forces.Here is a look at Gen. Mark Alexander Milley’s four years as the 20th chairman of the Joint Chiefs of Staff, based on interviews with the general, his colleagues and associates, as well as reporting and books about the Donald J. Trump administration.The First CrisisSept. 30, 2019On an Army base field just outside Washington, General Milley takes the oath of office.It is a rainy Monday, and President Trump is there. He has told his aides that General Milley, a barrel-chested Green Beret with bushy eyebrows and a command-a-room personality, looks like a proper general to him.“I have absolute confidence that he will fulfill his duty with the same brilliance and fortitude he has shown throughout his long and very distinguished career,” Mr. Trump says.The honeymoon does not last three days.General Milley, left, was sworn in during a ceremony with Vice President Mike Pence, President Donald J. Trump and other military leaders.Anna Moneymaker/The New York TimesOct. 4, 2019General Milley’s Turkish counterpart, Gen. Yasar Guler, tells him that Turkey will send thousands of troops over the border into Syria to target American-backed Kurdish forces. The Kurds are the Pentagon’s most reliable partners in the fight against the Islamic State. But Turkey says they are terrorists.General Milley has to take the matter to Mr. Trump, who is mad that U.S. troops are in Syria.Two days later, Mr. Trump announces a de facto endorsement of the Turkish move: He will pull the American troops out of Syria, essentially leaving the Kurds to fend for themselves.“Morally reprehensible and strategically dumb,” opines Senator Angus King, independent of Maine.Oct. 16, 2019An emergency meeting with Speaker Nancy Pelosi; Senator Chuck Schumer, the Democratic leader; and members of Mr. Trump’s national security team degenerates into a shouting match over Mr. Trump’s decision to pull the U.S. troops out of Syria.“Nervous Nancy’s unhinged meltdown!” Mr. Trump says after the meeting, tweeting a photo of Ms. Pelosi standing across a table from him, pointing her finger in the air.At the Pentagon, the talk is all about the man seated next to Mr. Trump in the photo: a grim-looking General Milley, with his hands clasped in front of him. He has been on the job for 16 days.Oct. 26, 2019Mr. Trump’s abrupt withdrawal order forces General Milley and Pentagon officials to speed up a plan to take out the ISIS leader, Abu Bakr al-Baghdadi, whom they have been monitoring at a compound in Qaeda territory in Syria.They want to carry out the risky nighttime raid while they still have troops, spies and reconnaissance aircraft in the country.The raid is successful, thanks in part to the same Kurdish forces Mr. Trump effectively abandoned.“He died like a dog,” Mr. Trump says of the ISIS leader.Nov. 13, 2019General Milley has figured out a way to turn Mr. Trump around on Syria. He has told the president that American commandos and their Kurdish allies need to stay to guard the oil there.Some 800 troops will remain in northern Syria.“We’re keeping the oil,” Mr. Trump tells reporters. “We left troops behind, only for the oil.”Jan. 3, 2020General Milley and other senior officials have given the president a range of options to deal with attacks by Iranian-backed Shiite militias. Mr. Trump chooses the most extreme: assassinating Gen. Qassim Suleimani, Iran’s most powerful military commander.Mr. Trump has been fuming over television reports showing Iranian-backed attacks on the U.S. Embassy in Baghdad.That night, General Suleimani is killed in an American drone strike at Baghdad International Airport.The fallout is immediate. Iranian groups put a price on General Milley’s head. And five days later, just after concluding a barrage of retaliatory airstrikes, Iran mistakenly shoots down a Ukrainian passenger jet, killing 176 people on board.General Qassim Suleimani, Iran’s most powerful military commander, was killed in an American drone strike.Abedin Taherkenareh/EPA, via ShutterstockWomen mourning General Suleimani during a funeral procession in Baghdad.Ahmed Jalil/EPA, via ShutterstockPandemic and ProtestsMarch 24, 2020At a virtual town hall event, General Milley predicts that the coronavirus will not last long. “You’re looking at probably late May, June, something in that range,” he said. “Could be as late as July.”That same day, the Navy announces that three sailors on the aircraft carrier Theodore Roosevelt have tested positive for the virus.May 25, 2020Memorial Day. More than 350 sailors from the Theodore Roosevelt are in quarantine on Guam. The virus has taken the aircraft carrier out of service for weeks, causing an imbroglio that leads to the resignation of the acting secretary of the Navy.Back in Washington, General Milley is heading to Arlington National Cemetery, where he will meet with Gold Star families who had lost loved ones in America’s wars.For General Milley, Memorial Day is a workday. He helps place flags on the graves. “I have soldiers that are buried here that died under my command,” he tells a CBS News crew.That night he sees a report on TV about a Black man in Minneapolis who died at the hands of the police.June 1, 2020“Can’t you just shoot them? Shoot them in the legs or something?” Mr. Trump asks General Milley and Defense Secretary Mark T. Esper in the Oval Office.Mr. Trump says that demonstrations in the streets over the killing of George Floyd were making him look “weak.” He wants 10,000 active-duty troops in Washington, D.C., alone to take on the protesters.General Milley and Mr. Esper explain that pitting American soldiers against American protesters could hurt civil-military relations and incite more violence. They talk Mr. Trump out of it.General Milley leans into Mr. Esper, presses his thumb to his forefinger and whispers that he is “this close” to resigning. So was Mr. Esper, the defense secretary recalled in his book, “A Sacred Oath.”It is not even noon yet.Around 6 p.m., General Milley and Mr. Esper are again summoned to the White House. Neither knows why at the time, but they will soon be taking a walk with the president.Mr. Trump has decided to stage a photo op in front of St. John’s Episcopal Church across Lafayette Square near the White House. He holds a Bible, which his daughter Ivanka has pulled out of her bag. General Milley is wearing his camouflage uniform.As Mr. Trump poses, General Milley disappears from view. But the damage is done. General Milley is the most senior officer of a military that at its core is supposed to be above politics.“An egregious display of bad judgment, at best,” says Paul D. Eaton, a retired major general and a veteran of the Iraq war.General Milley spends the rest of the night walking through the streets of Washington, talking to National Guard troops and protesters alike. At 12:24 in the morning, he heads home. Not long after, he is writing a resignation letter.“It is my belief that you are doing great and irreparable harm to my country,” one draft says, according to “The Divider: Trump in the White House,” by Susan Glasser and Peter Baker. He does not send the letter.Protests that sometimes turned violent erupted in Minneapolis and across the country after the police killing of George Floyd.Stephen Maturen/Getty ImagesGeneral Milley joined Mr. Trump and other senior officials in a walk from the White House, through protesters and law enforcement, to a church nearby.Doug Mills/The New York TimesJune 11, 2020General Milley apologizes for the walk in the park. “I should not have been there,” he says in a commencement address at the National Defense University.Mr. Trump is furious. “Why’d you do that?” he asks General Milley later that day.This is the Rubicon that many people in the Trump administration eventually cross: the moment when they change from ally to enemy in the eyes of the president. Mr. Trump never cared much for Mr. Esper, whom he calls “Mr. Yesper.” General Milley, by contrast, the president once favored. No more.Aug. 20, 2020General Milley is in Colorado Springs for a Northern Command ceremony and makes a beeline for Mr. Esper to tell him about an alarming phone call the night before: Robert C. O’Brien, Mr. Trump’s fourth national security adviser, says there is interest in killing another senior Iranian military officer.Why now? General Milley tells Mr. Esper the proposed strike has not gone through the normal bureaucratic discussion that precedes operations of this magnitude. To put Mr. O’Brien off, General Milley goes into what he calls his “hamana hamana,” nonsense talk.For the next five months, General Milley tells people that he will do everything he can to keep the Trump team from launching strikes — potential acts of war — without proper vetting.Oct. 14, 2020General Milley and Mr. Esper huddle over what to do about some military nominations they want to make.They want two women — Gen. Jacqueline D. Van Ovost of the Air Force and Lt. Gen. Laura J. Richardson of the Army — to be promoted, on merit, to elite, four-star commands. But the men are worried that Mr. Trump will not go for it, because promoting women is too “woke” for him.They agree on a strategy. They will hold back the nominations until after the November elections. Maybe Joe Biden will win, the men figure.Oct. 30, 2020General Milley reassures his Chinese counterpart, Gen. Li Zuocheng, in a phone call that Mr. Trump has no plans to attack China, no matter what intelligence is picking up about the president wanting to create a crisis to help him in the polls.Before the InsurrectionNov. 9, 2020Mr. Trump has lost the election but is not conceding. And he has decided that the transition period is a perfect time to revamp the Pentagon leadership. He takes to his usual medium to announce that he has “terminated” Mr. Esper. Christopher C. Miller, a former Army Green Beret, will take over the Defense Department.General Milley threatens to resign, according to Mr. Esper’s book. Mr. Esper tells him: “You’re the only one left now to hold the line. You have to stay.”Nov. 10, 2020The purge is on. Mr. Trump fires two Defense Department under secretaries and sends in political loyalists: Kash Patel, a former aide to Representative Devin Nunes of California, and Ezra Cohen, an ally of Michael T. Flynn, a former national security adviser. Anthony Tata, a retired general who once referred to President Barack Obama as a “terrorist leader,” is now in the top Pentagon policy job.General Milley vows that there will be no coup under his watch. “They may try,” but they will not succeed, Milley tells his deputies, according to “I Alone Can Fix It,” by Carol Leonnig and Philip Rucker. “You can’t do this without the military. You can’t do this without the C.I.A. and the F.B.I. We’re the guys with the guns.”Nov. 11, 2020During a meeting, Mr. Patel hands General Milley a sheet of paper that says Mr. Trump is ordering all remaining U.S. troops home from Somalia by Dec. 31 and from Afghanistan by Jan. 15.General Milley heads to the White House. He and other national security aides talk Mr. Trump out of the Afghanistan pullout by reminding him that he has already ordered an Afghanistan withdrawal in the next months. The Somalia withdrawal date is moved to Jan. 15.Nov. 25, 2020Mr. Trump removes Henry Kissinger and Madeleine K. Albright from the Defense Policy Board, replacing them with loyalists. He also pardons Mr. Flynn, the former general and national security adviser who pleaded guilty to lying to the F.B.I.A week later, Mr. Flynn endorses an ad calling for martial law and for a national “re-vote” — to be conducted by the military.“I just want to get to the 20th,” General Milley tells aides, referring to Inauguration Day, Jan. 20.Jan. 6, 2021Mr. Trump summons his supporters to the Capitol. Rioters storm the building to overturn the election.National Guard troops clashed with protesters into the evening on Jan. 6, 2021.Kenny Holston for The New York TimesNational Guard troops were stationed in the Capitol for weeks after the attack.Erin Schaff/The New York TimesJan. 8, 2021The Chinese are on high alert, so General Milley makes another call. “Things may look unsteady,” he says. “But that’s the nature of democracy, General Li.”Next, General Milley advises the Navy to postpone planned exercises near China.Ms. Pelosi is on the phone asking what’s to stop Mr. Trump from launching a nuclear weapon.General Milley tells her there are procedures in place.After that call, he summons senior officers to go over those procedures, according to “Peril” by Bob Woodward and Robert Costa. “If you get calls,” he tells the officers, “there’s a procedure.”He adds, “And I’m part of that procedure.”He turns to each officer in the room.“Got it?”“Yes, sir.”“Got it?”“Yes, sir.”A New BossJan. 20, 2021Joseph R. Biden Jr. takes the oath of office.April 6, 2021General Milley is in the Oval Office for the news he knows is coming but does not want to hear. Mr. Biden, like his predecessor, wants all American troops out of Afghanistan. This time, the deadline is Sept. 11, 2021, exactly 20 years after the terrorist attacks that launched two decades of war.General Milley had hoped that Mr. Biden would agree to keep a modest troop presence in the country to prevent it from falling back into the hands of the Taliban and from becoming a launching pad for terrorist attacks. But Mr. Biden is adamant.General Milley and the new defense secretary, Lloyd J. Austin III, tell senior commanders to start packing up. The last thing the men want now is for an American soldier to die in Afghanistan after the president has ordered a withdrawal.A race to the exits begins.General Milley and other leaders meeting with President Biden at the White House in October 2022.Doug Mills/The New York TimesJune 23, 2021General Milley pushes back against criticism that the Pentagon is becoming too “woke.”After a Republican congressman presses Mr. Austin, the first Black man to lead the Pentagon, on whether the Defense Department teaches “critical race theory,” General Milley hits back. “I’ve read Mao Zedong. I’ve read Karl Marx. I’ve read Lenin,” he says. “That doesn’t make me a communist.”In a two-minute clip that plays over and over on social media platforms, General Milley defends the military’s right to study what it wants, including topics that some might find uncomfortable.“I want to understand white rage, and I’m white, and I want to understand it,” he says. “What is it that caused thousands of people to assault this building, and try to overturn the Constitution of the United States of America?”Last Days in AfghanistanJuly 2, 2021American troops leave Bagram Air Base, their last hold in Afghanistan. Within hours, the base is ransacked by looters.Aug. 15, 2021The Taliban seize Kabul, the capital. Attention turns to evacuating Americans and their Afghan allies from the country.At the Pentagon, General Milley receives hundreds of phone calls from aid organizations, media companies and lawmakers, all pleading for help evacuating their people. In meetings, he barks at the bureaucratic red tape.Taliban fighters took control of Kabul on Aug. 15, 2021.Jim Huylebroek for The New York TimesAmerican Air Force troops evacuated scores of people from Kabul.Senior Airman Taylor Crul/U.S. Air Force, via ShutterstockAug. 26, 2021At 5:48 p.m. local time, a suicide attack at Kabul airport kills at least 183 people, including 13 U.S. service members sent to help with evacuations.Sept. 1, 2021General Milley is fielding questions at a news conference about a drone strike in Kabul that killed 10 civilians, including children. Senior officials know that civilians were killed, but they are sticking to the talking points that the strike also targeted terrorists plotting another attack.“Yes, there were others killed,” General Milley says. “Who they are, we don’t know. The procedures were correctly followed and it was a righteous strike.”Sixteen days later, the Pentagon acknowledges that the strike was a mistake.“This is a horrible tragedy of war,” General Milley says in a statement.Sept. 28, 2021The general has been talking.A bunch of books are out that describe his actions in the waning days of the Trump presidency: the call to China, the meeting with the nuclear code officers.Some senators at a hearing are angry that General Milley tried to protect the Pentagon from Mr. Trump. Others are angry that he told so many people afterward.In a break from usual military hearings on Capitol Hill, it is the Republicans who are angriest at the military general. General Milley is now a lightning rod for Trump allies across the country, regularly pilloried in right-wing media outlets.War in EuropeJan. 28, 2022General Milley warns that Russia has assembled more than 100,000 troops at Ukraine’s borders, with more coming every day, and enough military hardware to invade the entire country.Given the type of forces that are arrayed, he says at a Pentagon news conference, “if that was unleashed on Ukraine, it would be significant, very significant, and it would result in a significant amount of casualties.”Feb. 24, 2022Russia invades Ukraine.Ukrainian soldiers in Kharkiv, Ukraine, in February 2022.Tyler Hicks/The New York TimesRefugees arrived in Hungary after Russia invaded Ukraine.Mauricio Lima for The New York TimesOct. 24, 2022For the first time in months, General Milley is on the phone with his Russian counterpart, Gen. Valery V. Gerasimov, who had been giving him the silent treatment.U.S. intelligence has picked up discussions among senior Russian generals about using a tactical nuclear weapon in Ukraine. President Vladimir V. Putin of Russia has been making not-veiled threats about escalation, and General Milley wants to make sure Moscow isn’t about to cross a serious red line.After the call, General Milley’s people say that he and General Gerasimov will keep the lines of communication open.Nov. 9, 2022General Milley tells the Economic Club of New York that neither Russia nor Ukraine, in his opinion, can win the war. Diplomats, he believes, need to start looking for ways to begin negotiations.“When there’s an opportunity to negotiate, when peace can be achieved, seize it,” he says.The remarks cause a furor: Ukrainians worry that the Biden administration is preparing to abandon them, and White House officials scramble to reassure them that U.S. support remains solid.Feb. 11, 2023The text from a reporter comes to General Milley’s phone at 9:27 on a Saturday morning.For the third time in less than a week, NORAD is tracking an unidentified flying object over North America. This one is over the Yukon in Canada. U.S. fighter jets shot down the two others: a Chinese spy balloon, and who knows what.“It’s an alien, isn’t it,?” the text says.The general replies, “Not aliens!”Aug. 21, 2023The Royal Edinburgh Military Tattoo, a yearly show where troops clad in full ancient fighting kit including kilts, sporran, drums and bagpipes, put on a show at a centuries-old castle that has turned into a 90-minute farewell salute to America’s senior general.General Milley, in full military dress and white gloves, is in the guest-of-honor seat, in a crowd of thousands. As each group concludes its performance, a single green light in the darkened arena shines on the general, and he stands up, at attention. Each succession of troops stops to salute him. The green light goes off, and he sits back down.Sept. 22, 2023Mr. Trump has his own farewell salute for General Milley.In a Truth Social post, Mr. Trump says the general’s retirement “will be a time for all Americans to celebrate!” He calls General Milley a “woke train wreck” and complains about the general’s calls with his Chinese counterpart. “This is an act so egregious that, in times gone by, the punishment would have been DEATH!”Mr. Trump concludes, “To be continued!” More