Mahmoud Ahmadinejad announced Tuesday he has decided not to run again for president, saying he will instead remain a "little foot soldier of the revolution."
Hardliner Ahmadinejad, 59, was Iranian president for eight years until 2013, a time in which the country became increasingly isolated from the international community.
Supreme Leader Ayatollah Ali Khamenei, who has the final say on all state matters in the Islamic Republic, had spoken out against Ahmadinejad's potential return to the presidency.
Reports earlier this week said that while Khamenei had not issued a formal ban on the candidacy, he had advised the ex-president in a private meeting not to stand in the election, set for May 19, 2017.
The ISNA news agency reported Tuesday that Ahmadinejad wrote Khamenei a letter to say he would not seek the office.
"I'm not going to compete, and will remain a little foot soldier of the revolution and servant of the people," he wrote.
Ahmadinejad had hinted at his potential comeback several times since the start of the year and has expressed his desire to topple the current incumbent, reformist Hassan Rowhani.
After a drubbing by the reformists in parliamentary elections in February, many hardliners saw Ahmadinejad as the only hope for toppling Rowhani, but Khamenei's intervention extinguished those hopes.
The populist Ahmadinejad could potentially have exploited Rowhani's failure to reap the economic benefits from a groundbreaking nuclear deal with the international community in July 2015.