Iran on Monday removed its top national security official, one of the most powerful men in the country, after he came under scrutiny over his close ties to a high-ranking British spy.

The security official, Ali Shamkhani, had been secretary of the Supreme National Council, which shapes Iranian security and foreign policy, for a decade and before that worked at the defense ministry. the spy, Alireza Akbaria dual British citizen, Mr. Shamkhani’s deputy at the ministry and then worked as an adviser to him in the council.

In 2019, when suspicions about Akbari arose, Shamkhani lured him back to Iran from Britain, where he had moved, leading to his arrest and execution in January.

Mr. Shamkhani appeared to have not only survived but thrived after the scandal until his sudden ouster on Monday. In March, he led Iran’s negotiations to reestablish ties with Saudi Arabiawith China’s mediationand he also acted as a diplomat traveling to the neighboring countries of the Persian Gulf to strengthen trade and political relations.

But on Monday, the Islamic Republic showed once again that even its most loyal servants are not immune from being ousted from power. In a decree, Iran’s Supreme Leader, Ayatollah Ali Khamenei, removed Shamkhani from his post and thanked him for his service. He replaced him with a senior Revolutionary Guard naval commander with little experience in civilian politics.

Last June, Iran also removed the head of the Guards’ intelligence unit, Hossein Taebafter a series of covert attacks and assassinations in Iran linked to Israel suggested that Iranian intelligence circles had been compromised.

Iranian analysts said a number of controversies had contributed to Mr. Shamkhani was deposed.

He was charged with corruption amid allegations that his family raked in millions of dollars through an oil shipping company that helped Iran evade sanctions. He was also blamed for the failure of talks to revive the 2015 nuclear deal.

The council was also criticized for its handling of domestic unrest in the the months-long rebellion that called for the ousting of the ruling priestswith the majority of Iranians seeing Mr. Shamkhani complicit in the violent strikes which killed hundreds of protesters – and with supporters of the government criticizing his leadership for not being tough enough.

In addition, the hardline faction that now controlled parliament and the presidency saw him as too close to the previous governments, which were centrist and reformist, and therefore distrusted him.

“Pressure was building on Khamenei from the hardline faction and public opinion to remove Mr. Shamkhani,” Gheis Ghoreishi, a political analyst close to the government, said in a telephone interview from Iran. “He resisted for a while but the lobbying got too high.”

When Khamenei announced the dismissal, he said he appointed Mr. Shamkhani to a member of the Expediency Council, which largely advises the Supreme Leader. The appointment is seen as largely ceremonial; in recent years, other officials who had fallen out with Khamenei, including former president Mahmoud Ahmadinejad, have also been appointed to the council to save face.

Shamkhani’s ability to weather the spy scandal storm as long as he did may have been the result of a deal between Khamenei and Iranian President Ebrahim Raisi, analysts said.

“There was a give-and-take agreement between President Raisi’s government and the Supreme Leader to allow Shamkhani to redeem his public position after the Akbari scandal with the Saudi deal,” a political analyst, Sasan Karimi, said in a press release. interview from Tehran.

In a separate decree on Monday, Khamenei gave the Supreme National Council post to Gen. Ali Akbar Ahmadian, 62, a former deputy commander-in-chief of the Guard’s naval unit and a veteran of the Iran-Iraq war. He was described by Iranian media as a top military strategist who was also responsible for coordinating the Guards’ armed forces.

Although Khamenei always has the final say on major state policies, from negotiations with the United States to the domestic uprising against the ruling clerics, the role of the national security adviser is influential, analysts said. General Ahmadian does not have much experience in foreign policy or domestic national security issues.

“Shamkhani’s successor has no experience of working with anyone outside the military,” said Ali Vaez, Iran’s director of the Crisis Group. “It’s a steep learning curve. There could be a reset or delays on key issues like the future of the nuclear deal, the detention talks with the US and regional diplomacy.”