In speeches, he favors the “nation” and the “people” over the “ummah,” or community of believers, a term preferred by Iran’s clerics, who constantly guard against any revival of pre-Islamic nationalism. He has also said he is ready for talks with the United States, something other Iranian leaders strongly oppose under current circumstances.

Mr. Ahmadinejad regularly brings up the topic of corruption by other officials, and he hints that they have accumulated wealth and power because of their positions. “Some of the relationships, which had been formed as a result of groupings and power-mongering pursuits in the country, have come to an end, and with the help of God will be purged from the revolution and the holy Islamic republic,” he asserted recently.

The president has also taken to using the slogan “long live spring” in his speeches, which some have interpreted as an allusion to the Arab Spring uprisings. “This way of thinking and talking about ‘Human Awakening’ is political mischief and dangerous,” one newspaper wrote in an editorial.

Mr. Ahmadinejad’s maneuvering is all about his legacy, experts say, an effort to preserve both his political power and his allies.

“In effect, the president has created a new current in Iran’s political establishment,” said Reza Kaviani, an analyst at the Porsesh Institute, which is aligned with Iran’s former president,Ali Akbar Hashemi Rafsanjani, a moderate opponent of Mr. Ahmadinejad. “He has organized himself, placed bureaucrats in key positions. He will outlive his two terms, and so will his friends. But how he will remain and at what costs is unclear for now.”

Mr. Ahmadinejad’s support of Mr. Mashaei, his spiritual mentor and the father-in-law of his son, is a particular stick in the eye for the conservatives, as well as a subtle appeal to more progressive Iranians. In messages filled with poetic language, Mr. Mashaei repeatedly propagates the importance of the nation of Iran over that of Islam.

Leading ayatollahs and commanders say that Mr. Ahmadinejad has been “bewitched” by the tall, beardless 52-year old, whom they have called a “Freemason,” a “foreign spy” and a “heretic.” They accuse Mr. Mashaei of plotting to oust the generation of clerics who have ruled Iran since the 1979 Islamic Revolution and of promoting direct relations with God, instead of through clerical intermediaries. He and his allies, they say, are part of a “deviant” current.