The president, who was elected on a platform of improving relations with the West and escaping crippling economic sanctions, has been seen as vulnerable to a challenge from Iran’s hard-liners, for failing to deliver on his promises. Many sanctions remain in place even after the signing last year of a nuclear deal, primarily because of what the United States says is Iran’s support for terrorism and human rights violations.

Tehran denies those accusations, but no European or American bank will finance business with Iran as long as the sanctions remain in effect, unless the United States Treasury specifically certifies the deal, as it did for recent contracts with Airbus and Boeing.

Image Former President Mahmoud Ahmadinejad is seen as part of Iran’s hard-line faction. Credit Vahid Salemi/Associated Press

Mr. Ahmadinejad’s two presidential terms, from 2005 to 2013, were defined by confrontation with global powers, especially the United States. He is widely admired by the rural poor but is despised by the middle class majority. Corruption grew substantially during his tenure, and it continues to be a major problem today.

Experts say most of the profits from record-high oil prices during Mr. Ahmadinejad’s years were pumped around the state apparatus or were invested in ambitious housing projects that now stand empty in desert plains, without proper utilities or transportation infrastructure.

He has been credited, however, with cutting a bloated state subsidy system.

Ayatollah Khamenei made the statement about Mr. Ahmadinejad during a lecture for seminary students at his office. He was responding to rumors, circulating in Tehran for weeks, that he had barred Mr. Ahmadinejad from participating in the coming election.