“In following the will of the great leader of the revolution, I have no plans to be present in next year’s presidential competitions,” he wrote in a letter to Ayatollah Ali Khamenei published by Iranian media.
It came a day after Khamenei, in his own cautiously worded remarks, said: “A certain person came to me and I told him not to do a certain thing, believing it would be to the benefit of both the person himself and the country.”
Khamenei implied that Ahmadinejad’s candidacy would create “a bi-polar atmosphere” that would “damage the country”.
The hardline former president had made numerous public appearances in recent months, leading to speculation that he was planning a comeback in elections next May.
The news is likely to reassure moderate President Hassan Rouhani, who is expected to run for a second term on May 19.
Ahmadinejad’s inflammatory rhetoric — particularly regarding Iran’s nuclear programme and hostility towards Israel — was blamed for deepening tensions with the West, but his populist approach and humble roots means he has retained popularity with poorer sections of Iranian society.
Rouhani, who oversaw a deal with world powers to end sanctions in exchange for curbing Iran’s nuclear programme, faces mounting pressure from conservatives who say the accord has brought few benefits to Iran.