The targeted killing of Iranian Quds Force commander Qassem Soleimani last week broke an old taboo: Finally a US president held Iran ­responsible for the proxies it uses to kill Americans. It was a strategic victory for President Trump and an opportunity to roll it into a political masterstroke, as well — the immediate and complete withdrawal of US troops from Iraq.

For three years, Trump’s foreign policy has had to balance the two different Republican constituencies he courted during the 2016 campaign. To the isolationist wing, Trump promised no more regime-change wars in the Middle East that sent American troops to bring democracy to those shooting at them. Candidate Trump also promised GOP hawks and the overwhelmingly pro-Israel evangelicals that he’d undo President Barack Obama’s catastrophic nuclear deal with Iran.

Now that Trump has brought down the Islamic Republic’s top military commander and terror mastermind, he can reconcile the two wings of the party by declaring mission accomplished and dropping the mic. America’s work here is done.

It shouldn’t be a tough decision to make.

Despite the thousands of American lives and billions of US dollars sacrificed to ­remake Iraq, Tehran has more influence with Baghdad than Washington does. Of late, brave young Iraqis have taken to the streets to protest against their corrupt rulers and Iranian-backed Shiite militias. Since September, more than 500 Iraqis have been killed for opposing the Iranian satrap-state that rules them.

May their courage bring them the success they will have to earn on their own. After nearly 17 years, it is clear Washington can’t fix other nations.

America doesn’t need to be in Iraq to ­advance and maintain its Mideast interests. We have bases throughout the region, from the eastern Mediterranean to the Gulf. The drone that killed Soleimani was dispatched from Qatar. America also has many allies it can call on, like stalwart Jordan, Saudi Arabia and above all Israel, as well as our more problematic NATO partner Turkey.

Those who advocate staying in Iraq are arguing largely from an admirable but impractical principle — the US must not cut and run. From that perspective, surrendering Iraq would give Soleimani one final victory from beyond the grave.

In reality, a US withdrawal is more likely to cause problems for Tehran. The departure of US forces would restore the regional dynamics to their natural state, in which Iran is a Persian Shiite power surrounded by a sea of Sunni Arabs, more keen for revenge than ever, after the depredations suffered over the last two decades in Iraq as well as Syria.

It was only reluctantly that Obama redeployed troops to Iraq in 2014 after ISIS murdered two American journalists. He was focused on his signature foreign policy initiative — the Iran nuclear deal.

In time, Obama came to see the anti-ISIS campaign as a way to join US and Iranian interests. Together they would fight ISIS — or any Sunni that the Iranians defined as ISIS. In effect, US troops were used as a constabulary force to police Iraq on behalf of Tehran’s new Middle East order, stretching from the Straits of Tiran to the port of Beirut.

That was the situation from which Trump desperately wanted to extricate the United States. The Beltway bureaucracy, primarily the Departments of Defense and State, boxed him in. They had too much money and institutional power invested in programs requiring a US presence in Iraq. The Iranians were happy to have American forces stay in Iraq, so long as they kept their weapons pointed at Sunnis in open rebellion against the Baghdad government.

When Trump re-imposed sanctions crippling the Iranian economy, Soleimani ­directed Iraq’s Shiite militias to target US forces and eventually the American ­Embassy; he wanted to break the president’s will. Since the takeover of the US embassy in Tehran, the Islamic Republic had enjoyed more than 40 years of success running variations of that play against Washington.

How could Soleimani have known that rather than dispatch an envoy to bargain with Tehran’s slick-talking diplomatic corps, the world’s most famous deal-maker would ­instead rain fire on him?

In taking down Soleimani, Trump carved out his own exit strategy. It would be a pity to squander the historic triumph he earned last week: Soleimani’s killing lets us get out of the Iraqi quagmire on a high note.

Lee Smith is author of the bestselling new book “The Plot Against the President.”