Iran has foiled attempts by its foreign enemies to turn legitimate protests into an insurgency to overthrow the Islamic Republic, supreme leader Ayatollah Ali Khamenei said on Tuesday.

Comments on his Twitter feed and in Iranian media underscored the establishment's confidence that it has extinguished the unrest that spread to more than 80 cities in which at least 22 people died since late December.

"Once again, the nation tells the U.S., 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.'" Khamenei tweeted.

The Revolutionary Guards, the military force loyal to Khamenei, said on Sunday security forces had put an end to the unrest that it said had been whipped up by foreign enemies.

At least 1,000 people have been arrested in the biggest anti-government protests for nearly a decade, with the judiciary saying ringleaders could face the death penalty.

Khamenei said U.S. President Donald Trump was grandstanding when he tweeted support for protesters he said were trying "to take back their corrupt government" and promising "great support from the United States at the appropriate time!"

The Iranian leader tweeted: "... this man who sits at the head of the White House - although, he seems to be a very unstable man - he must realize that these extreme and psychotic episodes won't be left without a response."

As well as Washington and London, Khamenei blamed the violence on Israel, exiled dissident group People's Mujahedin of Iran and "a wealthy government" in the Gulf, a reference to Iran's regional rival, Saudi Arabia.

In a rare public appearance, the head of Israeli intelligence agency Mossad said the protests were due to Iranian President Hassan Rouhani's failure to improve people's economic or social circumstances, but he said they were unlikely to overthrow the establishment.

"In Iran too, we have eyes and ears," Yossi Cohen told a Finance Ministry conference in Jerusalem.

"One shouldn't develop high hopes, though I would be happy to see a meaningful revolution," he added.

Khamenei has called the protests - which were initially about the economy but soon turned political - "playing with fireworks", but he said citizens had a right to air legitimate concerns, a rare concession by a leader who usually voices clear support for security crackdowns.

"These concerns must be addressed. We must listen, we must hear. We must provide answers within our means," Khamenei was quoted as saying, hinting that not only the government of Rouhani, but his own clerical leadership must also respond.

"I'm not saying that they must follow up. I am also responsible. All of us must follow up," Khamenei said.