The Iranian response to the killing of Qassem Soleimani seems to have been a mix of extreme internal discombobulation — witness the ­funeral stampede, the apparently accidental downing of a passenger plane — and calculated prudence.

The discombobulation suggested just how shocked the Iranians were by the severity of President Trump’s response to months and months of Tehran’s attacks and provocations.

The toothlessness of Iran’s missile response surprised everybody who was fearing or predicting or weirdly rooting for worse (since worse would have demonstrated that Trump had been reckless and bad).

It shouldn’t have been surprising. The purpose of the Soleimani strike was to make it clear that the world’s foremost power would no longer tolerate the ­increasingly intense provocations and offenses Iran had aimed in our direction for four decades and especially the half-year leading to the Soleimani killing.

Whatever the mullahs are, they aren’t foolish. They pushed, and then they pushed some more, and then they pushed Washington and Trump too far — and their response demonstrates that they know it. The Tehran regime had no way to know what America might do in response to a serious counterassault, and so it didn’t make a serious effort.

As a high-ranking US official said to me this week, “the Iranians learned what Jeb Bush and Marco Rubio learned in 2016. Nobody out-escalates Donald Trump.”

It was — so far — a spectacularly effective effort to establish deterrence on Trump’s part. There are two ways this happened. One had to do with the elimination of the specific threat posed by Soleimani.

A senior diplomat told me ­intelligence reports suggested that Soleimani was the most radical of the Iranian leaders, the one who pushed the hardest for the most extreme actions. If so, his departure from the scene ­silences a powerful confrontational voice at the Iranian table — and thus the killing was a deterrent act in itself.

It may be true that if you kill one terrorist mastermind, another will rise in his place. But the fact is that masterminds like Soleimani do not grow on trees. If you think of him as the Steve Jobs of state-sponsored terror, then it seems plausible to likely that he will be followed by a less creative type — the Tim Cook of terror, say.

The second aspect of Trump’s success has to do with the nature of deterrence ­itself. It is sensible to expect that Iran isn’t finished with its response to the Soleimani killing — that at some point in the near to not-so-near future, it will strike at Americans and American interests somewhere.

Iran’s method of enacting terror against Israel has been to hit at Jews and Israelis far away — blowing up the Jewish center in Buenos Aires in 1994 or a bus full of Israeli tourists in Bulgaria in 2012. We might expect to see some version of that approach.

But horrendous as that would be when it happens, it wouldn’t vitiate the effort to deter Iran.

Deterrence isn’t designed to eliminate a threat — it can’t, by definition — but rather to manage it over a long period of time.

For example: Our post-World War II relationship with the ­Soviet Union was designed to deter its territorial ambitions and its potential use of nuclear weapons.

That didn’t mean the Soviet Union cooperated with our goals. No, it tested us and the world constantly through all kinds of means — funding Communist revolutions across the planet, ­using proxy forces to destabilize other countries and the like.

This was called the Cold War for a reason. It wasn’t a state of peace by any means. But we didn’t engage in direct hostilities. Rather, when we could, we countered Soviet moves, applied counterpressure to Soviet aggression and used our financial superiority as a lever.

America deterred the Soviets from attacking us, attacking NATO and attacking our allies in the Far East. And as the theory of containment had promised, these efforts over time made it clear within the Soviet Union that its own system was unworkable — and it collapsed.

Trump has made it clear that the collapse of the Islamic Republic isn’t his goal; he doesn’t do regime collapse. What he wants is for Iran to stay non-nuclear permanently — which President Barack Obama’s disastrous nuclear deal, with its decade-long window now half-gone, wouldn’t have accomplished.

Trump’s determination to deter Iran rather than cozy up to it might represent exactly the sort of pressure that could bring the mullahs to the table to make a real nuclear deal that doesn’t reward them for their egregious behavior.

jpodhoretz@gmail.com