Iran has dismissed an angry warning from US President Donald Trump that Tehran risked dire consequences "the like of which few throughout history have suffered before" if it made threats against the United States.

Iranian Foreign Minister Mohammad Javad Zarif hit back at Mr Trump's warning, which the US leader delivered written in capital letters in a late-night tweet.

"COLOR US UNIMPRESSED: The world heard even harsher bluster a few months ago. And Iranians have heard them albeit more civilized ones for 40 years. We’ve been around for millennia and seen fall of empires, incl our own, which lasted more than the life of some countries," Mr Zarif wrote on Twitter.

"BE CAUTIOUS!" he wrote in capital letters, echoing exact words from Mr Trump.

Iran has been under increasing US pressure and possible sanctions since Mr Trump's decision in May to withdraw the United States from a 2015 agreement between world powers and Iran over its disputed nuclear program.

Bitter foes since Iran's 1979 revolution, Washington and Tehran have cranked up talk of war in recent days.

The Trump administration has launched an offensive of speeches and online communications meant to foment unrest and help pressure Iran to end its nuclear program and its support of militant groups.

Despite the heightened rhetoric, both sides have reasons to want to avoid starting a conflict.

Mr Trump's words appeared to be in response to Iranian President Hassan Rouhani saying that hostile policies toward Tehran could lead to "the mother of all wars."

In his tweet directed at Mr Rouhani, Trump wrote: "Never, ever threaten the United States again or you will suffer consequences the likes of which few throughout history have ever suffered before. We are no longer a country that will stand for your demented words of violence & death. Be cautious!"

Mr Rouhani had told a gathering of Iranian diplomats on Sunday: "Mr Trump, don't play with the lion's tail, this would only lead to regret."

"America should know that peace with Iran is the mother of all peace, and war with Iran is the mother of all wars," said Mr Rouhani, quoted by the state news agency IRNA.

Mr Trump is under pressure from US policy makers for taking too soft a line against Russia in a summit last week with President Vladimir Putin.

His Iran tweet resembled ones he issued last year to warn North Korea over its nuclear weapons program.

At the White House, Mr Trump, in response to a shouted question about whether he had any concerns about provoking tensions with Iran, said he had none at all,

Although Mr Rouhani left open the possibility of peace between Tehran and Washington, Iran's most powerful authority Supreme Leader Ayatollah Ali Khamenei on Saturday ruled out negotiations with the United States as an "obvious mistake."

An anti-US sign in the Iranian capital Tehran

There is limited appetite in Washington for a conflict with Iran, not least because of the difficulties the US military faced in Iraq after its 2003 invasion but also because of the impact on the global economy if conflict raised oil prices.

Many ordinary Iranians are worried that the war of words might lead to a military confrontation but insiders in Tehran told Reuters they believed the Trump administration would not drag the United States into another quagmire in the Middle East.

Trump threatens former US officials' security clearances

The White House has threatened to strip six former US intelligence and law enforcement officials of their security clearances.

It comes as Mr Trump considers striking back at critics of his summit meeting last week with Russian President Vladimir Putin.

Among the six are Obama-era CIA director John Brennan, former senior US officials James Comey, James Clapper, Michael Hayden, Susan Rice and Andrew McCabe.

White House spokeswoman Sarah Sanders said Mr Trump is "exploring the mechanisms" to remove the security clearances.

Ms Sanders said the officials have "politicised and in some cases monetised their public service and security clearances, making baseless accusations of improper contact with Russia or being influenced by Russia."

After Mr Trump gave credence following his summit in Helsinki to Mr Putin's denials about Russian meddling in the 2016 US election despite findings by the American intelligence community, Mr Brennan called Trump's remarks "nothing short of treasonous."

In his 16 July Twitter post, Mr Brennan added, "Not only were Trump's comments imbecilic, he is wholly in the pocket of Putin."

Mr Trump fired Comey as FBI director last year and he has become a prominent critic, calling the US president "morally unfit" for office.

Mr Clapper, who stepped down as director of national intelligence before Mr Trump took office last year, has accused the president of placing American democratic institutions "under assault."

Mr Hayden is a former director of the CIA and National Security Agency. Ms Rice was former President Barack Obama's national security adviser. Mr McCabe, who as the former No. 2 FBI official was involved in the agency's investigation of Russia's role in the 2016 US election, was fired by Attorney General Jeff Sessions in March.

Many former US officials retain their security clearances after they leave government service because they continue to advise their former agencies or because it is a condition of employment as government contractors or consultants. Stripping the clearances also represents a public rebuke of the officials and severs a connection with the intelligence community.

Asked if Mr Trump was punishing the former officials because of their criticism, Ms Sanders said, "No, I think you are creating your own story there."

Trump came under a torrent of criticism after Helsinki, including from many in his own Republican party.

One of the few who publicly sided with him last week, Senator Rand Paul, said he met with Trump on Monday and asked him to revoke Mr Brennan's security clearance.