Iran will hold a run-off election after hardline candidate Saeed Jalili and rival Massoud Pezeshkian, who is seen as reformist, both failed to secure a majority in the presidential race.
Candidates need to win 50% of the vote but the pair both hovered around the 40% mark - with Mr Pezeshkian finishing narrowly ahead.
Iran's interior ministry confirmed the second round is set for 5 July.
Two security force members were killed after unidentified gunmen attacked a vehicle carrying election boxes in Sistan-Baluchestan province, according to state media reports.
Former nuclear negotiator Mr Jalili was trailing Mr Pezeshkian - a former heart surgeon and health minister - by about a million votes, early results from the interior ministry show.
Mr Pezeshkian has promised a different approach, saying the actions of the morality police, who enforce strict dress codes on women, are "immoral".
Although he is seen as a reformist, Mr Pezeshkian is deeply loyal to Iran's supreme leader. Some commentators have suggested that should he be elected, Iran should not expect more than a difference in tone.
The vote is to replace former president Ebrahim Raisi, who died on 19 May when the helicopter he was in crashed into a mountain, with seven other people also killed.
Though there are 61.5 million eligible voters in Iran, only around 40% turned out to vote - the fewest since the 1979 Islamic revolution.
Supreme leader Ayatollah Ali Khamenei, who is the ultimate authority in the country, had called for “maximum” turnout.
Iran was shaken by a huge wave of protests in 2022 following the death of 22-year-old Mahsa Amini, who was detained by the morality police for allegedly violating Iran's strict dress code.
Human rights groups say hundreds were killed in the crackdown and thousands detained.