A hardline cleric once thought to be a possible successor to Iran’s supreme leader has been appointed head of the Islamic Republic’s judiciary, sparking concern from rights activists over his involvement in the execution of thousands of people in the 1980s.

Ebrahim Raisi was named to the post in a decree by Ayatollah Ali Khamenei, the semi-official Fars news agency reported.

Raisi’s selection comes after he was trounced by incumbent Hassan Rouhani in the country’s 2017 presidential election. Some analysts suggest that loss and other concerns means the move takes him out of the running to replace Khamenei as supreme leader. Khamenei turns 80 in July.

Speculation that Raisi could be named to the post also sparked criticism from the US, which under Donald Trump has withdrawn from Tehran’s nuclear deal with world powers.

Raisi, “involved in mass executions of political prisoners, was chosen to lead #Iran’s judiciary. What a disgrace!” Robert Palladino, a deputy State Department spokesman, tweeted. “The regime makes a mockery of the legal process by allowing unfair trials and inhumane prison conditions. Iranians deserve better!”

Rumors began months ago that Khamenei would appoint Raisi, 58. He will replace Sadegh Amoli Larijani, a conservative cleric who is the brother of Iran’s parliamentary speaker, Ali Larijani. Khamenei had appointed Larijani as the head of the country’s Expediency Council, which mediates differences between the country’s parliament and its guardian council, Iran’s constitutional watchdog.

Khamenei has praised Raisi, a former Iranian attorney general, in the past.

In 2016, Khamenei appointed Raisi to run the Imam Reza charity foundation, which manages a vast conglomerate of businesses and endowments in Iran. It is one of many bonyads, or charitable foundations, fuelled by donations or assets seized after Iran’s 1979 Islamic Revolution.

These foundations offer no public accounting of their spending and answer only to Iran’s supreme leader. The Imam Reza charity, known as Astan-e Quds-e Razavi in Farsi, is believed to be one of the biggest in the country. Analysts estimate its worth at tens of billions of dollars.

Raisi’s appointment to the foundation led analysts to speculate that Khamenei could be grooming Raisi as a possible candidate to be Iran’s third supreme leader.

Activists, however, hold a very different view of Raisi because of his alleged involvement in the 1988 mass execution of prisoners at the end of Iran’s long war with Iraq. After Iran’s then-supreme leader Ruhollah Khomeini accepted a UN-brokered ceasefire, members of the Iranian opposition group Mujahedeen-e-Khalq (MEK), heavily armed by Saddam Hussein, stormed across the Iranian border in a surprise attack.

Iran ultimately beat back the assault, but the attack set the stage for the sham retrials of political prisoners, militants and others that would become known as “death commissions”. Some who appeared were asked to identify themselves. Those who responded “mujahedeen” were sent to their deaths, while others were questioned about their willingness to “clear minefields for the army of the Islamic Republic”, according to a 1990 Amnesty International report.

International rights groups estimate that as many as 5,000 people were executed, but the MEK puts the number at 30,000. Iran has never fully acknowledged the executions, apparently carried out on Khomeini’s orders, though some argue that other top officials were effectively in charge in the months before his 1989 death. Raisi reportedly served on a panel involved in sentencing the prisoners to death.