Donald Trump has threatened Iran with “consequences the likes of which few throughout history have ever suffered before” in a Twitter tirade that has stunned diplomatic observers.

The all-caps tweet came after the Iranian President Hassan Rouhani spoke out on America’s anti-Iran policy.

Mr Trump told Mr Rouhani to “never, ever threaten the United States again” and told him to “be cautious!”.

Mr Rouhani had cautioned Mr Trump about pursuing hostile policies against Tehran, saying “America should know … war with Iran is the mother of all wars”.

“Mr Trump, don’t play with the lion’s tail, this would only lead to regret,” Mr Roiuhani said on Sunday, according to local news outlet IRNA.

Tehran faces increased US pressure and looming sanctions after Mr Trump’s decision to withdraw the United States from a 2015 international deal over Iran’s nuclear program.

Iranian President Hassan Rouhani on Monday morning (AEST) cautioned Mr Trump about continuing to pursue hostile policies against Tehran.

Mr Rouhani had left open the possibility of peace between the two countries, at odds since the 1979 Islamic Revolution.

“You are not in a position to incite the Iranian nation against Iran’s security and interests,” he added, in an apparent reference to reported efforts by Washington to destabilise Iran’s Islamic government.

Mr Trump is still working to regain the support of his Republican party after being widely criticised for his perceived soft approach to Russian President Vladimir Putin at their summit in Helsinki last week.

That meeting culminated a fractious European trip that saw him criticise Germany over its reliance on Russia, demand America’s NATO allies spend more on defence and ridicule British Prime Minister Theresa May’s Brexit deal,

In Washington, US officials familiar with the matter said that the Trump administration had launched an offensive of speeches and online communications meant to foment unrest and help pressure Iran to end its nuclear programme and its support of militant groups.