The 6-mile-long downtown Enghelab, or Revolution Street, in Tehran was decorated with huge balloons as loudspeakers blared out revolutionary and nationalist songs to encourage people to join the rallies.
State TV showed a cartoon of the Shah being thrown into the "dustbin of history", wearing clothes in USA colours and holding Iranian newspapers headlined "The Shah has left!"
The march culminated at Azadi Square, where President Rouhani addressed the crowd.
Prices of basic foodstuffs have soared since President Donald Trump withdrew Washington from world powers' 2015 nuclear deal with Iran past year and reimposed sanctions on Tehran.
Iranians thronged streets across the country, many with portraits of Ayatollah Ruhollah Khomeini, the Shiite cleric who toppled the Shah in the historic Islamic uprising.
Netanyahu quickly fired back on Monday night, saying that if Tehran attacks Israel, it will be the last anniversary of the Islamic Revolution that they celebrate. "Terrorizing its own people and terrorizing the world", Bolton said. Tehran denies the charge, insisting its satellite launches and rocket tests do not have a military component.
Journalist Mikey Kay recalled in this vein that Bolton has spoken at least eight times at rallies organised by MEK (Mojahedin-e Khalq), an Iranian dissident group which calls for regime change in Iran and is known to pay up to $50,000 per speech.
Rouhani also promised that Iran would overcome its economic hardships, worsened by the restored US sanctions.
Elsewhere, the head of the elite Quds Force of Iran's powerful Revolutionary Guard, Gen. Qassem Soleimani, attended the rally in the southern city of Kerman. He said he wanted to teach his son to support the revolution. "My mother, despite her illness, asked me to bring her out", he said.
"On the revolution's 40th anniversary we are at the top for scientific achievements like nanotechnology or accurate missiles", he said.
"Much to the dismay of America, the revolution has reached its 40th year", read one banner. "I don't think you'll have many more anniversaries to enjoy", Bolton said.
Last week, Iranian Supreme Leader Ayatollah Khamenei claimed that Iran's infamous "Death to America" chanting is intended not at the United States as a whole, but merely at President Trump.
"Perhaps worst of all, the people of Iran have suffered grievously".
"I bow in admiration to Iran's resilient people who - despite hardships and grievances - today poured into streets by the millions to mark 40th anniversary of their Islamic Revolution, which some in the USA wished would never come", Iranian Foreign Minister Mohammad Javad Zarif tweeted.