But the pro-government rallies, planned for 1,200 cities and towns, according to the state media, were overshadowed in intensity by Iranians in Tehran shouting, “Death to the dictator” and “Clerics should get lost,” witnesses said.
Others chanted: “Shame on you, Seyyed Ali Khamenei,” using an honorific for the supreme leader. “Let the country go.” Some protesters burned a banner with an image of his face.
Video shared on social media on Saturday showed Iranians directly calling for Mr. Khamenei to step down, and also chanting, “Referendum, referendum, this is the slogan of the people.” (After the 1979 revolution, the Islamic Republic was established with a referendum.)
Overtly political demonstrations are rare in Iran, where security services are omnipresent, and officials called on the crowds to halt them.
The Interior Ministry urged Iranians on Saturday “not to participate in these illegal gatherings as they will create problems for themselves and other citizens,” according to the BBC.
The Revolutionary Guards, which along with its Basij militia spearheaded a crackdown against protesters in 2009, said in a statement carried by state news media on Saturday that efforts were underway to replicate that unrest, and that Iran “will not allow the country to be hurt.”
Later in the evening, the police fired tear gas to disperse crowds protesting at Tehran’s central Vali-e Asr Square, a witness said.
About 4,000 people, meanwhile, turned out for the annual pro-government rally in the capital, state media reported. State television stations showed marchers carrying banners in support of Mr. Khamenei in Mashhad, Iran’s second-largest city.
Typically, pro-government demonstrations are orchestrated by the state, and many of those attending are bused in. The rallies took on added significance after the unauthorized demonstrations — the largest protests in years — began over the rise in the price of food supplies.
“Young people are angry and frustrated, without a hope in the future,” said Nader Karimi Juni, a reformist journalist. “If they join these small groups of determined students, there could be a real problem.”
President Trump tweeted support for the protesters, saying the government should respect the people’s right to express themselves. “The world is watching!” Mr. Trump said.
A spokesman for the Ministry of Foreign Affairs, Bahram Qassemi, condemned the statement by the president, and another by the State Department supporting the protesters, as “meddlesome” and “opportunistic.”
In a rare move, state television broadcast images of the protests on Saturday, acknowledging that some people were chanting the name of Iran’s one-time shah, who fled into exile before its 1979 Islamic Revolution.
As some social media users called for more antigovernment rallies in Tehran and other cities later Saturday, demonstrations broke out in cities like Karaj and Zanjan, where a crowd tore down a billboard with a portrait of Mr. Khamenei.
On Saturday night, the messaging app Telegram closed the account of the Iranian channel Amad News after government officials complained directly to the company’s chief executive that the channel was encouraging violence.
The messaging app is widely used in the country and some analysts said the protesters were organized in part on the platform and others like it.
Mohammad-Javad Azari Jahromi, Iran’s Minister of Information and Communications Technology, in a tweet urged the head of Telegram, Pavel Durov, to shut down the channel.
The channel was shut down, and Mr. Durov offered an explanation, also on Twitter, saying that Amad News had broken the messaging app’s rules against encouraging violence.
Early Saturday afternoon, about 30 students standing behind the fences of Tehran University shouted at passers-by, asking them to join in the protest, witnesses said. The students chanted a slogan against both reformists and hard-liners:
“This is the end of their adventure,” meaning the Islamic Republic.
The hard-line Fars news agency tweeted a response, saying that “opportunists are trying to raise unrest in front of Tehran University.”
Security forces arrested a few people from a crowd of hundreds that had gathered on sidewalks in the capital. Some protesters threw stones.
The protests were the first major demonstrations since the 2009 demonstrations, and they appeared to be steered by reformist politicians who had challenged the re-election of Mr. Ahmadinejad.
The results of the vote set off more than six months of protests, with three million people protesting in the early days. Pro-reform groups, including the grass-roots Green Movement, said the vote had been rigged.
Mr. Rouhani’s re-election has emboldened Iranians seeking reforms. But his pledges to improve the economy have been hampered by the cumulative effect of sanctions and decades of government mismanagement.
At the pro-government rally on Saturday, one demonstrator, Ali Ahmadi, 27, blamed the United States for Iran’s economic problems, according to The Associated Press.
“They always say that we are supporting Iranian people, but who should pay the costs?” he said.
When the unauthorized protests began on Thursday in Mashhad, a city of two million in the northeast, some protesters shouted, “Death to Rouhani.”
Vice President Eshaq Jahangiri, a reformist ally of the president, said that hard-line conservative opponents of Mr. Rouhani might have galvanized the first protests but lost control of them.
“Those who are behind such events will burn their own fingers,” the state media quoted him as saying.
Tehran’s deputy governor-general for security and law enforcement, Mohsen Hamedani, dismissed reports that officials planned to impose a curfew in Tehran, the semiofficial ISNA news agency reported.
Analysts said that the general discontent could spur more protests in coming days, or that the demonstrations may die down.
In the capital, where middle-class Iranians tend to set the tone, many residents strongly disapprove of some of Iran’s leaders and have been hurt by the bad economy. But they fear insecurity and unrest even more, experts say.
“The middle-classes like me are scared of losing what they have,” Mr. Juni said. “They won’t join the protests, I think.”