Secretary of State Mike Pompeo speaks to the press during a tour of the newly inaugurated Al-Fattah Al-Alim mosque in Egypt's new administrative capital 28 miles east of Cairo on Thursday. (Andrew Caballero-Reynolds/AFP/Getty Images)

Jim Mattis and Nikki Haley — the two Trump Cabinet members least blemished by their service — got out just in time. The longer the administration’s foreign policy officials stay in office, the more foolish they look serving a president who undercuts them with willful perversity. Case in point: the withdrawal of U.S. troops from Syria.

As recently as Jan. 6, national security adviser John Bolton had said that the withdrawal, which President Trump had announced on Dec. 19, would not occur until the Islamic State was defeated and the Kurds protected — conditions that might not be met for years. But when Bolton showed up in Turkey to seek a deal this week, Turkish President Recep Tayyip Erdogan pointedly refused to meet with him and denounced Bolton’s attempt to attach conditions to the U.S. withdrawal as a “serious mistake.” It didn’t matter: On Friday, U.S. forces began pulling out of Syria anyway, suggesting that the era of the Pentagon trying to sidestep Trump’s temper tantrums is finished. Once the troops are gone, America’s Kurdish allies will be left at the Turks’ mercy and the Islamic State will be free to rise again.

In the administration’s internecine battles, you can chalk this up as a victory for Secretary of State Mike Pompeo, who has insisted all along that U.S. troops are coming out just as the president said. But Pompeo looked foolish — and petty, too — with his hyperpartisan foreign policy speech in Cairo on Thursday. It was full of unseemly attacks on the previous administration — whatever happened to politics stops at the water’s edge? — but it actually amounted to a massive self-own.

“We learned that when America retreats, chaos often follows. When we neglect our friends, resentment builds. And when we partner with enemies, they advance,” Pompeo said. It’s hard to find anything better than that as a description of the Trump policy in Syria. The United States is retreating from the one-third of Syria that its troops effectively controlled in partnership with the Syrian Democratic Forces, and chaos is likely to follow. In the process the United States is neglecting its friends — the Kurds and Israelis — and partnering with its enemies, Iran and Russia.

Trump even said on Jan. 3 that Iran will have free rein in Syria: “They can do what they want there, frankly.” That’s very different from Pompeo’s fatuous pledge in Cairo that the United States will “work with our partners to expel every last Iranian boot” from Syria. With the removal of U.S. troops, the amount of territory that Iran and Russia can control will vastly expand. The Kurds are already asking Syrian President Bashar al-Assad — Tehran and Moscow’s man in Damascus — for protection.

Is this really the foreign policy that Mike Pompeo and John Bolton signed up to promulgate? They were both known at one time as fire-breathing foes of anti-American regimes and advocates of U.S. military interventions. Bolton even advocated preventative strikes on Iran and North Korea. Now they have become yes-men and enablers for a president who is instinctively predisposed toward isolationism and appeasement of dictators.

Just imagine how Pompeo and Bolton would be lambasting a President Hillary Clinton if she had held a summit with North Korean dictator Kim Jong Un, said she had fallen in love with him and refused to call him out for expanding his nuclear and missile arsenals even while pledging to “denuclearize.” They would be apoplectic, and rightly so. But because it’s their boss appeasing North Korea, they are silent — at least in public. What about in private? That’s harder to say, but there is no indication that they are strongly pushing back on the president’s fantasies because they know the fate that has befallen previous officials who have tried to do that. Just ask former secretary of state Rex Tillerson and former national security adviser H.R. McMaster.

When Pompeo and Bolton have tried to slow Trump’s rush into Kim’s arms, they have been rudely slapped down. Bolton suggested that North Korea follow the “Libya model” of complete nuclear disarmament before the United States lifted sanctions. Kim reacted strongly, threatening to scupper a summit, and Trump tossed Bolton under the bus, saying, “The Libya model isn’t the model that we have at all when we’re thinking of North Korea.”

Or recall what happened when Pompeo traveled to Pyongyang in July to follow up on the Singapore summit and attain from North Korea a list of their nuclear facilities and a timeline for dismantlement. Kim refused to see the secretary of state (he visited a potato farm instead), and the Foreign Ministry denounced Pompeo’s “gangster-like” demands. Instead of backing up his secretary of state, Trump meekly truckled to Kim’s tirade. “Complete, verifiable and irreversible denuclearization,” once the administration mantra, is now off the table, and Trump is preparing to reward Kim for his intransigence with a second summit.

At some point, Bolton and Pompeo need to ask themselves what they are doing in an administration that does violence to nearly every belief they have spent their careers advocating. Maybe they are restraining Trump from doing even worse. Or maybe they are just closing their eyes to the ugly reality that they are complicit because they enjoy the perks and prestige of high office.

Read more:

The Post’s View: Mike Pompeo lambastes Obama — and then embraces Obama’s Syria strategy

Asli Aydintasbas: The Syria deal Trump should strike

Henry Olsen: Trump is now forging foreign policy on his own. Where will he take us?

Jennifer Rubin: After two years Trump is more ignorant on foreign policy