A hardliner has been elected chairman of Iran's Assembly of Experts, a clerical body which chooses and monitors the country's supreme leader.
Ayatollah Mohammad Yazdi defeated moderate former President Akbar Hashemi Rafsanjani, winning 47 out of 73 votes.
Correspondents say the ayatollah was not seen as a frontrunner for the post.
He will head the assembly until next February, when direct elections for all 86 of its members will coincide with national parliamentary polls.
The move comes at a sensitive time, with rumours circulating about the health of the 75-year-old Supreme Leader, Ayatollah Ali Khamenei.
Rafsanjani 'not prepared'
The responsibilities of the Assembly of Experts are to appoint the supreme leader, monitor his performance and remove him if he is deemed incapable of fulfilling his duties.
Monday's election was prompted by the death in October of its former chairman, Ayatollah Mohammad Reza Mahdavi Kani, considered a unifying figure in Iranian politics.
Analysis: Sebastian Usher, Middle East editor, BBC World Service
The election of Ayatollah Yazdi is undoubtedly a blow for former President Rafsanjani and for the more moderate faction of Iran's ruling elite.
It is something of a surprise, too, as Ayatollah Yazdi was not seen as a frontrunner. Another prominent cleric, Ayatollah Mahmoud Shahroudi, had been touted as a likely compromise candidate, but withdrew before the vote.
It comes at a sensitive time, not just as talks over a deal on Iran's nuclear programme reach a critical stage, but also as speculation is rife over the health of the supreme leader himself. Publicly discussing his successor is taboo in Iran, but the jockeying for power is clearly underway.
Ayatollah Yazdi was among five contenders whose names had been linked to the post by Iranian media, but he was not the most talked about, according to the AFP news agency.
The 83 year old served as a deputy speaker of parliament after the 1979 Islamic Revolution and headed the judiciary for a decade until 1999.
He received almost two times more votes than Mr Rafsanjani, who previously served as chairman of the Assembly of Experts between 2007 and 2011.
In an interview published by the reformist Shargh newspaper on Tuesday, he had appeared reluctant to take on the post, saying his work with the Expediency Council, an advisory body for the Supreme Leader that adjudicates in disputes over legislation, was keeping him busy.
"Psychologically, I am not at all prepared to become the chairman of the Assembly of Experts," he said. "I work enough at the Expediency Council and why would it be necessary to work more than this?"
He added: "My criterion is that it should be someone who befits the stature of the Assembly of Experts."