He emerged attired not as a clandestine spy, or in the starred uniform of a military leader, but in flowing robes typical of Shia clergy. Intelligence Minister Hojatoleslam Seyyed Mahmoud Alavi informed the assembled media in the measured tones of a cleric in April that “tens of spies” serving in sensitive centers in Iran had been arrested.

Alavi’s comments were part of a steady escalation of tensions that has the United States and Iran on the brink of armed conflict: On Wednesday, a government spokesman announced that Iran had “uncovered” a cyber spy network in what appeared to be a repeat of Alavi’s April announcement. On Thursday, Iran’s Revolutionary Guard Corps (IRGC) shot down a U.S. drone but said it held back from taking out a manned aircraft. Later that day, according to U.S. President Donald Trump, airstrikes on a target in Iran were “cocked and loaded” — but he changed course when he learned there could be 150 casualties.

In the middle stands the 65-year-old cleric, Alavi. An unlikely spy chief, he is emblematic of the multiple power centers vying for control within Iran. He is widely seen as close to Ayatollah Ali Khamenei, Iran’s supreme leader. Yet at the same time, as a minister, he is the sword arm of reformist President Hassan Rouhani’s turf war with Tehran’s hardliners. And there’s a third ball he needs to juggle: the IRGC.

Iran’s first line of defense if attacked, the IRGC is also in charge of spreading Iran’s influence across the Middle East through proxy militias. When threats against Iran mount, the IRGC’s influence grows: It has virtually taken control of large parts of the country’s domestic and foreign policy in recent years, says Ramin Jahanbegloo, an Iranian philosopher and professor at the O.P. Jindal Global University near New Delhi. Both the government and the supreme leader are wary of the IRGC’s rising clout. Their man tasked with challenging the revolutionary guards is Alavi.

Either he conceals his smarts associated with a professional intelligence boss or he is a simple religious preacher in the wrong job. A diplomat who has known Mahmoud Alavi

In April 2017, Alavi publicly criticized the IRGC for its arrests of reformist users of the messaging platform Telegram, which, while not legal in Iran, is still being used by everyone who matters in the country. The same year, he publicly defended the daughter of the head of the judiciary, Sadeq Amoli Larijani, who had been accused by the IRGC of spying for a foreign power, and an official who negotiated the nuclear deal in Geneva, Abdolrasoul Dorri-Esfahani. With the IRGC’s profile expected to rise amid the tensions with the U.S., Alavi’s role as a principal troubleshooter for Khamenei and Rouhani — who have their own significant differences — is only expected to grow. The best way to check the IRGC’s legitimacy? Demonstrate that the government intelligence forces are adept at tackling the U.S.

“Neither Alavi nor any of the Iranian ministers are doing a good job,” says Jahanbegloo. “They all have to follow the line of the supreme leader, which means a hard line against the U.S.”

In April, Alavi claimed to have broken up a CIA-led ring of 290 spooks, preempting attempts of these networks to recruit local people as spies. True to the business of intelligence, Alavi offered no evidence against these “spies,” instead using fear against those who sympathize with the West or are seen to oppose the Iranian government. That extends to the tactic of shutting down anti-regime Telegram channels — never mind that Alavi has accused the IRGC of heavy-handed behavior with social media users.

Alavi is the point man to watch on Iran’s restless youth who seek more political openness. His agents also recently came down heavily on Christians after he controversially claimed that Christianity was gaining popularity in Iran. The cross from a 100-year-old Assyrian Presbyterian church was taken away and the building padlocked.

The move was a sign of how Alavi’s religious background influences his intelligence work. Even Alavi had expressed surprise when Rouhani appointed him as the intelligence minister in 2013. Due to his proximity with Khamenei, he was expecting some other assignment that would fit his experience as a religious teacher. Just before his present job as spy-in-chief of the Iranian government, Khamenei had designated Alavi as the head of the political conscience of the army — making sure its religious commitment remained steadfast.

The son of an ayatollah (high-ranking cleric), Alavi went to Ferdowsi University, in the city of Mashhad (a popular pilgrimage site), and earned a Ph.D. in Islamic jurisprudence. Alavi also went to Qom, the religious headquarters of the Shia revolution of Iran, working in the office of the first post-revolutionary leader, Ayatollah Khomeni. In 2011, his candidacy to the parliament was rejected by the powerful, conservative Guardian Council on the bizarre grounds of “noncommittal to Islam and the system.”

He ended up on Rouhani’s campaign committee in 2013. After he was appointed as intelligence minister, Alavi offered amnesty to political opponents based in foreign countries as part of Rouhani’s efforts to project himself as different from his hard-line predecessor, Mahmoud Ahmadinejad. Not many responded.

Some professionals in the intelligence business who have scrutinized Alavi closely find him “an ordinary cleric.” “Either he conceals his smarts associated with a professional intelligence boss or he is a simple religious preacher in the wrong job,” says a diplomat who met him years ago and asked not to be identified for fear of reprisals.

Many reformist protesters, though, accuse Alavi of human-rights violations and preventing legitimate political activity. Contrary to the common view in the West, Iran is a noisy democracy where Rouhani can be chased by aggressive reporters during press conferences in Tehran. Normally, the criticism against government ministers is sharp, but much has changed since the U.S. withdrew from the nuclear deal Tehran negotiated with global powers, which had promised sanctions relief in return for curbs on Iran’s nuclear program. Now dissent is seen as subversion.

Rouhani, who came in on the platform plank of signing the nuclear deal and reviving the battered economy, suddenly has to compete with fundamentalists, and that means turning Iran into a police state. “Iranian intelligence is very good. No intrusion by a foreign agency lasts beyond 24 hours,” claims an intelligence source who requested anonymity for fear of retaliation.

It doesn’t mean dissent is going away. Many of Rouhani’s young supporters believe the country has no business operating in Lebanon or Syria — where Alavi reportedly popped up recently to coordinate “resistance” to the pending U.S. peace plan for Israel. They’d rather the government focus on their internal ills. As Alavi’s crackdown shows, though, he has a different idea of internal ills.

Read more: Trump and Iran are climbing a shaky ladder of escalation.