Iran's supreme leader lashed out at the United States and Britain and vowed to respond against foreign powers he accused of attempting to overthrow the Islamic republic.

Ayatollah Ali Khamenei also took a shot at Donald Trump on Tuesday, accusing the US president of being "a very unstable man" who exhibited "extreme and psychotic episodes".

Iran says it has "hard evidence" the recent deadly demonstrations were "very clearly directed from abroad".

"US officials should know that, firstly, they have missed their target … Secondly, they have inflicted damage upon Iran in recent days, and they should know this won't be left without a response," Khamenei said on Twitter.

"Once again, the nation tells the US, Britain, and those who seek to overthrow the Islamic Republic of Iran from abroad that 'you've failed, and you will fail in the future, too.'"

At least 22 people were killed and about 3,700 arrested after anti-government protests erupted in the second-largest city, Mashhad, on December 28 and quickly spread throughout the country.

Iranian officials have accused the CIA and Israel's Mossad of masterminding the unrest, also alleging Saudi Arabia funded the operation.

CIA Director Mike Pompeo said allegations that his intelligence agency was involved in Iran's demonstrations were "false.

"It was the Iranian people … started by them, created by them, continued by them demanding a better set of living conditions and a break from the theocratic regime that has been with them since 1979," Pompeo told Fox News on Sunday.

The U.S. President says the Iranian establishment is terrified by their power. Well, if we were so terrified by you, how did we kick you out of Iran in late 70s and send you packing, out of the entire region, in the 2010s? — Khamenei.ir (@khamenei_ir) January 9, 2018

Khamenei also challenged Trump's assertion that Iran's establishment was frightened by American power.

"If we were so terrified by you, how did we kick you out of Iran in late '70s and send you packing out of the entire region in the 2010s?" the supreme leader said.

At the height of the protests, Trump described Iran as the "Number One State of Sponsored Terror with numerous violations of Human Rights occurring on an hourly basis".

{articleGUID}

He later tweeted: "The people of Iran are finally acting against the brutal and corrupt Iranian regime."

A close ally of Israel and Saudi Arabia - Iran's foremost enemies - the Trump administration has denounced Iranian influence in the Middle East and threatened to withdraw from the international nuclear deal with Iran.

The US government is expected to announce in the coming days whether it will recertify the landmark 2015 agreement - also involving China, Russia, Germany, France, and the UK - to curb Iran's nuclear weapons programme.

Trump has called the nuclear deal "the worst ever", though the International Atomic Energy Agency said Tehran has fully complied with the agreement.