To understand why John Bolton is no longer Donald Trump’s national security adviser, it’s worth looking back 37 years, to the departure of another hawkish appointee from another Republican administration. The adviser was Secretary of State Alexander Haig, and the president was Ronald Reagan.

When Bolton entered the Trump administration, he was determined to reverse what he saw as Iranian gains in the Middle East. When Haig entered the Reagan administration, he was determined to reverse what he saw as Soviet gains in Central America. And like Bolton, who has called for bombing Iran, Haig suggested that turning the communist tide in America’s hemisphere might require attacking Cuba. “Give me the word and I’ll make that island a fucking parking lot,” Haig told White House Deputy Chief of Staff Michael Deaver, according to Lou Cannon’s book President Reagan: The Role of a Lifetime. “You get a band of brothers from CIA, Defense, and the White House and you put together a strategy for toppling Castro,” he urged Deputy National Security Adviser Robert McFarlane.

If Haig believed his swagger would endear him to his boss, he was wrong. According to Deaver, Haig’s belligerence “scared the shit out of Ronald Reagan.” After Haig’s Cuba comments, Deaver worked to ensure that he never met Reagan alone. Haig lasted only 17 months in the job.

That’s how long Bolton lasted too. And for the same fundamental reason: Presidents who take office in the shadow of unpopular wars don’t tolerate warlike advisers for very long.

Reagan’s aversion to military action in Cuba had everything to do with Vietnam, a war that ended just six years before he took office. America’s defeat there left a chasm between a foreign-policy establishment that still believed in America’s Cold War commitments and a public weary of war. An article published the year before Reagan’s election noted that foreign-policy “opinion leaders” were 38 percentage points more likely than Americans as a whole to say the United States should deploy troops if the Soviets invaded western Europe, and 39 points more likely to support deploying them if the Soviets invaded Japan. As a result, Reagan—although happy to send money and arms to anti-communist rebels and regimes in Central America—was adamant that he would not send U.S. troops. Asked in 1982 what conditions might prompt him to deploy American forces to El Salvador, Reagan quipped, “Well, maybe if they dropped a bomb on the White House, I might get mad.”

While his Democratic critics called him a warmonger, Reagan understood that no administration—irrespective of ideology—could thrive in the post-Vietnam environment if it risked a protracted foreign war. When terrorists blew up the Marine barracks housing U.S. peacekeepers in Beirut in October 1983, Reagan’s poll numbers immediately fell. The following February, just days after launching his reelection campaign, Reagan decided to bring the marines home. “Once we pulled the troops out of Lebanon,” Reagan’s national campaign director later recalled, the election was “never close again.”

What was true for Reagan is true for Trump. He viscerally understands something that many of his party’s foreign-policy wonks do not: After Iraq, the public has little appetite for war. In the Republican primaries, this realization helped him defeat hawkish rivals such as Jeb Bush and Marco Rubio. “I’m the only one on this stage that said, ‘Do not go into Iraq,’” Trump boasted (falsely) at a debate in February 2016. At a rally a few days later, he invoked his supposed opposition to Iraq as evidence that he alone could be trusted not to launch new wars. “People talk about me with the button,” he exclaimed. “I’m the one that doesn’t want to do this.” Like Reagan, Trump understood that while Republican voters favored spending money on the military, they didn’t—absent a direct attack on Americans—want to use it. “We have to have a great military,” Trump declared early in the campaign, “but we have to focus on ourselves.”

Trump also understands something else: While many Republican foreign-policy wonks still favor a larger American military footprint overseas, the conservative-media ecosystem has shifted dramatically as a result of Iraq. The most prominent right-wing pundits are now more isolationist than interventionist. And these anti-interventionist pundits—who serve as a link between Trump and his base—constantly remind him that he campaigned on ending wars, not starting them.

Reportedly on the advice of the retired generals James Mattis, then his defense secretary, and H. R. McMaster, then his national security adviser, Trump bombed Syria in April 2017 in response to its government’s use of chemical weapons. Ann Coulter, a prominent Trump surrogate in 2016, responded by condemning the move in an appearance on Fox Business. “We have to get rid of all of these generals,” she demanded, before asking, “Were any of them paying attention to the Trump campaign?” That August, when Trump announced he would keep American troops in Afghanistan, an article in Breitbart—whose former executive chairman, Steve Bannon, ran Trump’s campaign—called the decision “a disappointment to many who had supported his calls during the campaign to end expensive foreign intervention.” When in December 2018 Trump announced the withdrawal of American troops from Syria—which prompted Mattis to resign— the Fox & Friends host Steve Doocy gushed, “This is one of the reasons people voted for him.”

The foreign-policy advisers who have survived in the Trump administration—including Secretary of State Mike Pompeo—have done so by adapting to this political reality. Bolton—an ideologue who as late as 2016 still claimed that the Iraq “invasion fully justified itself”—did not adapt. Which was why he lost his job.

Trump reportedly hired Bolton because he liked his pugnaciousness on Fox News. It didn’t hurt that Sheldon Adelson, Trump’s largest donor in 2016, is a Bolton fan. But Bolton kept pushing an interventionist line that contradicted both Trump’s political instincts and his love affair with the big deal. Bolton loudly denounced North Korean missile tests that Trump downplayed and opposed making concessions to get Pyongyang to freeze its nuclear program. He mused about military intervention in Venezuela while Trump was souring on the effort to oust its leader. He opposed a peace deal with the Taliban and negotiations with Iran despite Trump’s evident interest in both. “If it was up to John,” Trump reportedly said, “we’d be in four wars now.”

A key rupture occurred in June, after Iran downed an American drone. Bolton reportedly urged an American attack. After Trump called off the strike, the Fox News host Tucker Carlson called Bolton a threat to Trump’s reelection. “Donald Trump was elected president precisely to keep us out of disasters like war with Iran,” Carlson declared. “So how did we get so close to starting one? Simple. The neocons still wield enormous power in Washington. They don’t care what the cost of war with Iran is. They certainly don’t care what the effect on Trump’s political fortunes might be. They despise Donald Trump. Now one of their key allies is the national security adviser of the United States.”

Soon articles began suggesting that Bolton had lost his influence. Later that month, when Trump became the first American leader to enter North Korea, Bolton wasn’t with him. Carlson was.

That Trump is dumping Bolton just as he begins his own reelection campaign—just as Reagan withdrew U.S. troops from Lebanon in early 1984—comes as no surprise. As Americans learned last fall, when Trump made the migrant “caravan” the centerpiece of his midterm campaign strategy, the closer Trump gets to an election, the more he embraces his core political identity. Part of that identity is built on the belief that Americans still live in a war-weary, post-Iraq age.

Unfortunately for John Bolton, Trump’s belief just happens to be true.