The twinned elections for parliament and a leadership body called the Assembly of Experts are seen by some analysts as a potential turning point that could shape the future for the next generation, in a country where nearly 60% of the 80 million population is under 30.
The elections are the first since Tehran agreed with major powers to curb its nuclear program, leading to the removal of most of the stringent international sanctions that have paralyzed the economy over the past decade.
Turnout was heavy. Polling was extended five times for a total of almost six hours, because so many people wanted to vote.
Supporters of Rouhani, who championed the nuclear deal, are pitted against hardliners close to Supreme Leader Ayatollah Ali Khameni. They are deeply suspicious of detente with Western countries, seen as adversaries implacably opposed to the 1979 revolution that toppled the Shah.