On the 38th anniversary of Iran's Islamic Revolution, hundreds of thousands attended the rally, rife with anti-US and anti-Israeli sentiment.

Hundreds of thousands of Iranians rallied on Friday to swear allegiance to the clerical establishment following US President Donald Trump's warning that he had put the Islamic Republic "on notice", state TV reported.

On the anniversary of Iran's 1979 Islamic Revolution, which toppled the US-backed shah, marchers including hundreds of military personnel and policemen headed towards Tehran's Azadi (Freedom) Square. They carried "Death to America" banners and effigies of Trump, while a military police band played traditional Iranian revolutionary songs.

Supreme Leader Ayatollah Ali Khamenei, Iran's most powerful authority, had called on Iranians on Tuesday to take part in the demonstrations to show Iran was not frightened of American "threats".

State TV showed footage of people stepping on Trump's picture in a Tehran street.

"America and Trump cannot do a damn thing. We are ready to sacrifice our lives for our leader Khamenei," a young Iranian man told state TV.

Last week Trump put Iran "on notice" in reaction to a Jan. 29 Iranian missile test and imposed fresh sanctions on individuals and entities. Iran said it will not halt its missile program.

Pragmatist President Hassan Rouhani also called on Iranians to join the rally on Friday to "show their unbreakable ties with the Supreme Leader and the Islamic Republic".

"Some inexperienced figures in the region and America are threatening Iran ... They should know that the language of threats has never worked with Iran," Rouhani told the crowd at the Azadi Square. "They should learn to respect Iran and Iranians ... We will strongly confront any warmongering policies."

State television said millions had turned out at rallies across the country.

The Tehran ceremony was rife with anti-US and anti-Israeli sentiment. Some people carried pictures of Trump, Israeli Prime Minister Benjamin Netanyahu and British Prime Minister Theresa May captioned "Death to the Devil Triangle".

US flags were burned as is traditional although many Iranians on social media such as Twitter and Facebook used the hashtag #LoveBeyondFlags to urge an end to flag-burning during the anniversary.

They also thanked Americans for opposing Trump's executive order banning entry to the United States to travellers from seven mainly Muslim countries, including Iran. Trump's travel ban is being challenged in US courts.

Both US-based social media sites are blocked in Iran by a wide-reaching government censor but they are still commonly used by millions of Iranians who use special software to get around the restrictions. Iranian officials, including Khamenei, have Twitter and Facebook accounts despite the ban.

Trump has criticized a nuclear deal reached between Iran, the United States and other major powers in 2015 aimed at curbing the country's nuclear work.

Most of the sanctions imposed on Iran were lifted last year under the deal.