In a message of condolence for Saturday’s funeral of Ayatollah Abbas Vaez-Tabasi in Mashhad, Ayatollah Ali Khamenei, Iran’s supreme leader, said the departed cleric, who died the previous day aged 80, had been “a sympathetic brother…[and] comrade of difficult days”.

But Khamenei lost no time in appointing Ebrahim Raeisi, the 55-year-old national prosecutor-general, to follow Vaez-Tabasi as chairman of Astan Quds Razavi, the foundation that manages the shrine of Imam Reza in Mashhad.

Raeisi is a close ally of Khamenei, and his appointment will strengthen links between the leader’s office and the shrine, whose annual turnover – based on endowments, property and companies – is many billions of dollars. The leader has chosen another ally, Ahmad Alamolhoda, as his representative for Khorasan province, a second post left vacant by Vaez-Tabasi’s passing.

Vaez-Tabasi was close to former president Akbar Hashemi Rafsanjani, an ally of president Hassan Rouhani. Back in the 2005 election, the shrine backed Rafsanjani in his unsuccessful presidential bid, as did three of the city’s five parliamentary deputies.

Hojjatoleslam Ebrahim Raeisi, in black turban, with Ayatollah Jannati

Raeisi, who holds the clerical rank of hojjatoleslam, is a different character. At last year’s 36th anniversary of the taking of the embassy hostages, which featured criticism of the Rouhani administration as well as denunciations of the United States as the “Great Satan”, Raeisi announced that the intelligence and security forces had “identified and cracked down on a network of penetration in media and cyberspace, and detained spies and writers hired by Americans”.

Two years ago, Raeisi accused the west of promoting homosexuality around the world in the name of human rights, and he has also reportedly defended the amputation of the hands of thieves.

Since 2012 he has been prosecutor of the Special Court of the Clergy (dadgahe vijeh-ye rohaniyat), a body answerable to the leader that is outside the usual judicial process and has indicted several reform-minded clerics.

At the time of the 1988 executions of 3,000-5,000 political prisoners ordered by then leader Ayatollah Ruhollah Khomenei, Raeisi was deputy prosecutor in Tehran, a role he had held since 1984-5. On his website Raeisi says after Khomeini asked him to investigate certain provincial cases in the Iranian year 1367 (1988-89), he then handed him and Jaffar Nayyeri “important cases”.

Nayyeri is described in Tortured Confessions, the 1999 book by leading historian Ervand Abrahamian, as a special assistant to the Tehran special commission, set up alongside others, wrote Abrahamian, “with instructions to execute Mojaheds [members of the opposition armed group, Mojahedin-e Khalq] and leftists as mortads (apostates from Islam)…it was dubbed ‘the commission of death’. Similar commissions were set up in the provinces.”

As head of the shrine, Raeisi could play a huge role in the future succession to Khamenei, 76, as leader, especially as he is also a member for south Khorasan province of the Experts Assembly, the body that chooses the leader should a need arise.

The possibility of a succession to Khamenei in the next eight-year term of the Assembly added bite to last month’s election of the body on a day when Iranians also voted for a new parliament. The Experts Assembly poll saw a shift towards a “List of Hope” - drawn up by Rafanjani, Rouhani and former reformist president Mohammad Khatami – that found success in Tehran, encouraging tactical voting to successfully unseat Ayatollah Mohammad Yazdi, the assembly chairman, and the colourful Ayatollah Mohammad Taqi Mesbah-Yazdi.

The appointment of Raeisi is a reminder that the politics of the succession to Khamenei will be shaped not just by the popular election. “Ayatollah Vaez-Tabasi was very close to Hashemi [Rafsanjani] and very powerful,” Saeid Golkar, senior fellow at Chicago Council of Global Affairs and lecturer at Northwestern University, told Tehran Bureau.

Golkar is sceptical of analysing the Experts Assembly through a simple divide between “hardliners” and “moderates”, preferring to distinguish groups based around the “three pillars” of state bureaucracy, the clerical establishment in Qom and the military-security apparatus.

“There are those close to the more traditional clergy in Qom – like Ayatollah [Mahmoud Hashemi] Shahroudi and Ayatollah [Mohammad] Emami-Kashani. Secondly, there are clergy close to the Revolutionary Guards and security apparatus, like Sadegh Larijani and [Mohammed Mehdi] Mirbagheri. And thirdly, there are the clergy close to the bureaucracy and the state, like Hashemi [Rafsanjani] and Rouhani.”

Golkar concedes that some straddle the pillars, regarding Yazdi and Mesbah-Yazdi as “traditional clergy” linked to the “military-security” camp. While Raeisi has no links to the state bureaucracy and little standing among the clerical establishment in Qom, Golar suggests Raeisi’s links to the leader could put him closest to the military-security pillar.

And while Khamenei is an arbiter within Iranian politics, he is also a factional player and most powerful decision-maker, with beyt-e rahbari (leader’s office) expanding its scope since he took office in 1989.

Golkar thinks Khamenei’s base has shifted over time: “When Khamenei was president [1981-89], he was a middle-rank clergy closely related to the state bureaucracy, but after he became leader he expanded his relationship with the Revolutionary Guards (IRGC), expanding the Guards to five branches. He also attempted, less successfully, to expand his influence in the seminaries through greater regulation.”

The jury is very out on how far last month’s election to the Experts Assembly will shape the succession.

“The election does tell us something about the sentiments of the majority of Iranians in wanting to have a say in who should be selected as the leader,” Farideh Farhi, of the University of Hawaii, told Tehran Bureau. “But while this sentiment was expressed, in stunning ways in Tehran, it is not yet clear if it was heard or, if heard, whether it will be acted upon…The campaign prior to the election saw plenty of accusations, even by the leader himself, against those who publicly questioned the over-the-top vetting of registrants, including Hassan Khomeini, for being British agents or duped by the ‘enemy’.”

Golkar agrees that the Assembly of Experts cannot be treated in isolation: “The Assembly somehow reflects the wider society – the bureaucracy, the clerical networks, the security – so the succession will reflect what’s going on outside the Assembly of Experts as well, including the power balance between the executive, the judiciary and parliament…After the appointment of Raeisi [to chair the shrine in Mashhad], Ayatollah’s Khamenei’s office will be more powerful, but all of these political events have an impact, so we have to wait and see.”

With conservative critics of last July’s nuclear agreement licking their wounds after the election, Golkar has been monitoring their reactions on social media. “The majority accept there was defeat to Rouhani and his administration but say this is not the end of the road. They draw a comparison with the Khatami period [1997-2005, when the conservatives lost several elections]. They say, ‘We need to go away, reassess, and come back with a new strategy’.”

The Tehran Bureau is an independent media organisation, hosted by the Guardian. Contact us @tehranbureau