Four years ago, then-candidate Donald Trump vowed to keep America out of costly, perpetual wars in the Middle East. Last year, President Trump doubled down, declaring that Washington should “stop the endless wars.”

That was before Iran’s ayatollahs faced the most serious popular challenge to their misrule in four decades, in response to their blunderous shoot-down of a Ukrainian passenger jet and the ongoing repression and poverty that mark the lives of most Iranians. The question now is: Can US policy afford to tip the internal balance against the mullahs, even as Trump tries to extricate us from the region?

The answer is yes. These goals — regime change in Iran and ending endless wars — are, in fact, complementary.

The only durable, responsible way for the United States to leave the region is to see the Tehran regime replaced in the long term. Otherwise, Iran will continue to sow instability that will inevitably draw us back in. It’s up to Iranians to do the heavy lifting, but Americans can help.

From the heart of the Middle East, the Islamic Republic projects power into Mesopotamia, the Levant and the Arabian Peninsula. Its aims are to undermine US allies and dominate one of the most strategically crucial parts of the world in the image of Ayatollah Khomeini’s fanatical Shiite ideology. To this end, the Islamic Republic funds a network of terrorist proxies, including Hamas, Hezbollah and Islamic Jihad, the Houthi rebels in Yemen and Shiite militias that brutalize Iraqi Sunnis.

In September, the regime attacked Saudi petroleum facilities, bringing more than half of Saudi oil production to a halt. Then there is the Iranian nuclear-weapons program, worrisome in itself in a tinderbox region — doubly so in light of Iranian leaders’ not-infrequent threats to erase the world’s sole Jewish state from the pages of history.

The mullahs’ expansionist vision isn’t limited to their own neighborhood, moreover. In South America, Iranian proxy Hezbollah has forged ties with anti-American governments in Cuba, Venezuela, Bolivia and Ecuador. Hezbollah has even emerged as a global drug-trafficker, according to the Obama and Trump administrations, pushing tons of cocaine from Latin America plus heroin obtained from the Taliban into American cities.

Not only do Iran’s rulers have a presence in our backyard, but they also pose a direct threat to the homeland. Sleeper cells of Hezbollah’s Islamic Jihad Organization exist in the United States, and one such agent, Bronx-based Ali Kourani, was sentenced to 40 years in federal prison last year for staking out potential attack sites.

Then, too, the regime in Iran has helped grease the wheels of North Korea’s missile programs, and Tehran and Pyongyang collaborate to evade sanctions. The mullahs are also cozy with major US rivals Russia and China, working together to strategically undermine US interests regionally and globally.

Bottom line: We can diminish the nefarious influence of the ­Islamic Republic, but we can’t end it without ending the ­regime. Even a weakened regime in Iran continues to pose a national security threat to the US.

Now imagine a world in which Iranians have an accountable government that upholds their dignity and pursues prosperity. A world where Iran functions as a normal nation-state and works with Israel and the US as partners. Such a change would make it dramatically easier for us to decrease our regional footprint.

America can’t “fix” Iran. It can’t create a new regime for the Iranians. And no one expects that after the “nation-building” disasters in Iraq and Afghanistan. But Team Trump can assist Iranians — foremost, by not rushing to ink a new nuclear deal with a regime that is losing its grip by the day. Such a deal could stabilize the regime’s finances and prolong its life.

The policy of maximum economic pressure should continue, as it buys time for the opposition to organize itself around a clear vision for Iran’s future, one that is inclusive and nationalistic. More pressure on the regime will provide a space for Iranians inside and outside the country to merge their efforts and create the leadership that will be necessary to replace Iran’s current rulers.

Contrary to anti-Trump pundits’ claims, Trump’s words and deeds haven’t unified Iranians behind the regime. His most recent tweet in Persian, for example, was the most-liked tweet in that language in Twitter’s history. By continuing the economic pressure and steering clear of the regime’s bazaar-style nuclear tricks, Trump has a great chance of success. Success that only the likes of Ronald Reagan and Franklin Roosevelt have achieved in the history of American foreign policy.

Peter Kohanloo is president of Iranian-American Majority, where Ben Tabatabaei is a member of the board.