President Hassan Rouhani warned Sunday that war with Iran would be “the mother of all wars.” (AP)

Tension between the United States and Iran escalated Monday after President Trump appeared to threaten military action in a bellicose tweet and Iranian officials vowed to resist any attempt to destabilize their country.

The president issued his warning in an all-caps, late-night tweet to Iranian President Hassan Rouhani on Sunday, renewing speculation about a direct confrontation between the Trump administration and its chief adversary in the Middle East.

“NEVER, EVER THREATEN THE UNITED STATES AGAIN OR YOU WILL SUFFER CONSEQUENCES THE LIKES OF WHICH FEW THROUGHOUT HISTORY HAVE EVER SUFFERED BEFORE,” Trump told the Iranian leader. “. . . BE CAUTIOUS!”

The president’s threat came after Rouhani said earlier Sunday that war with Iran would be “the mother of all wars” and suggested that Tehran might flex its military might in Middle Eastern waterways that are crucial to global commerce.

Trump’s message exposed the disjointed nature of his administration’s strategy on Iran, as officials across the government continue to put economic and political pressure on Tehran despite the president’s sudden hint at a military strike.

Despite putting Iran “on notice” in the earliest days of Trump’s presidency, U.S. officials have shunned military moves that might bring an unwanted escalation and instead have opposed the international Iran nuclear deal and embraced a growing web of sanctions.

That indirect approach has so far failed to halt Iran’s ballistic missile program or check its support for proxy groups across the Middle East.

“There’s a huge gap between the objectives that have been laid out and the means the administration has so far been willing to employ,” said former envoy Dennis Ross, who has advised Republican and Democratic presidents on the Middle East. “At some point, either you revise the objectives or you embrace new means.”

Iranian Foreign Minister Mohammad Javad Zarif responded to Trump on Monday afternoon, tweeting that Iran was “UNIMPRESSED” by the president’s threat.

“The world heard even harsher bluster a few months ago. And Iranians have heard them —albeit more civilized ones—for 40 yrs. We’ve been around for millennia,” he said.

White House officials said Trump’s message to Iranian leaders was in keeping with his tough stance.

“The president’s been, I think, pretty strong since Day One in his language towards Iran,” press secretary Sarah Huckabee Sanders told reporters Monday. “He’s going to continue to focus on the safety and security of [the] American people.”

National security adviser John Bolton suggested in a statement issued Monday that Trump’s tweet might have been planned or at least contemplated for a while.

“I spoke to the president over the last several days, and President Trump told me that if Iran does anything at all to the negative, they will pay a price like few countries have ever paid before,” said Bolton, who has advocated regime change in Iran in the past.

Trump’s tweet followed a familiar pattern: When mired in an especially negative situation, change the subject.

So a week after his summit with Russian President Vladimir Putin, which was heavily criticized by Democratic and Republican leaders, and after waffling over his faith in U.S. intelligence agencies, Trump took to Twitter to issue an all-caps bulletin to Iran.

“There’s nothing going on here except he wants to change the subject,” said one Trump adviser, who spoke on the condition of anonymity to offer a candid assessment.

The adviser noted that Iran’s leaders have uttered similar “mother of all wars” taunts over the years and that little has substantively changed in recent days to indicate a real escalation of tensions.

Asked Monday if he had any concerns about stoking tensions with Iran, Trump told reporters, “None at all.”

The most recent war of words comes 2½ months after Trump set aside the concerns of America’s closest allies and pulled out of the nuclear deal with Iran on May 8, deeming the pact “an embarrassment.”

Since then, teams of U.S. officials have fanned out across Europe and Asia, warning companies to stop importing Iranian oil and to sever other types of business ties with Iran.

The Trump administration is also seeking to impose new financial costs on Iran, imposing sanctions on top officials and individuals associated with the Lebanese militant group Hezbollah.

A fresh round of sanctions targeting the Iranian automotive industry and key metals will go into effect Aug. 4, the State Department has said. Sanctions targeting Iran’s energy and banking sectors are due to be instituted Nov. 4.

The United States is also intensifying efforts to reach Iranians directly. Speaking to Iranian Americans in California on Sunday, Secretary of State Mike Pompeo announced that the U.S. government would expand broadcasts in Farsi and take steps to bypass Internet censorship in Iran.

Mark Dubowitz, who heads the Foundation for Defense of Democracies, said the administration’s harsh rhetoric together with economic measures had yielded some results, including reductions in Iran’s ballistic missile tests and harassment of foreign ships.

“What the president is trying to do with this tweet is what he’s succeeded in doing in the last year and a half, signaling to the Iranians: ‘Don’t test me; don’t close the Strait of Hormuz; don’t interfere with international shipping,’ ” Dubowitz said. “ ‘I will order [Defense Secretary Jim] Mattis to sink your ships.’ ”

But in the absence of a direct challenge from Tehran, few administration officials have supported pushing back militarily against Iran, even in places where groups trained and armed by Iran have directly challenged U.S. objectives, such as Syria, Yemen and Iraq.

While the United States has acted several times to halt direct threats against its forces in Syria, Pentagon leaders, including Mattis, have consistently opposed risking another costly Middle Eastern conflict as they seek to reorient the military toward threats from Russia and China.

Instead, they have advocated an indirect approach to countering Iran’s destabilizing activities, building up partner forces in Syria and Iraq and seeking to interdict weapons smuggled to Shiite rebels in Yemen.

Trump’s tough language and threats appear to mirror his approach to North Korea and the leader he ridiculed last year as “Little Rocket Man.” After a string of menacing statements, Trump and leader Kim Jong Un sat down for a high-profile summit in June.

But Karim Sadjadpour, an Iran expert at the Carnegie Endowment for International Peace, warned that those tactics may not succeed with Iran.

“Iranian officials tend to be more prideful. Unless [supreme leader Ayatollah Ali] Khamenei is facing significant economic distress and existential angst, I suspect he will avoid negotiations with the United States during the Trump era,” he said. “The depth of mutual mistrust and contempt is too great.”

Jarrett Blanc, who worked on Iran issues at the State Department during the Obama administration, said Trump’s threats did not appear to be connected to a larger plan making a case for war, similar to what occurred with Iraq before the U.S. invasion in 2003.

“I don’t think Donald Trump has decided, in the way George W. Bush and Cheney decided with Iraq, that ‘I’m going to go to war, and I’m going to build up this narrative and escalatory spiral to get me there,’ ” he said.

John Hudson, Carol Morello and Anne Gearan contributed to this report.