Early in his presidency, Ahmadinejad was sometimes described as "enjoy[ing] the full backing" of the Supreme Leader Ali Khamenei, and even as being his "protege."
In Ahmadinejad's 2005 inauguration the supreme leader allowed Ahmadinejad to kiss his hand and cheeks in what was called "a sign of closeness and loyalty," and after the 2009 election fully endorsed Ahmadinejad against protesters.
However, as early as January 2008, signs of disagreement between the two men developed over domestic policies, and by the period of 2010–11 several sources detected a "growing rift" between them.
The disagreement was described as centered on Esfandiar Rahim Mashaei, a top adviser and close confidant of Ahmadinejad and opponent of "greater involvement of clerics in politics", who was first vice president of Iran until being ordered to resign from the cabinet by the supreme leader.

In 2009, Ahmadinejad dismissed Intelligence Minister Gholam-Hossein Mohseni-Eje'i, an opponent of Mashaei.
In April 2011, another Intelligence minister, Heydar Moslehi, resigned after being asked to by Ahmadinejad, but was reinstated by the supreme leader within hours.
Ahmadinejad declined to officially back Moslehi's reinstatement for two weeks and in protest engaged in an "11-day walkout" of cabinet meetings, religious ceremonies, and other official functions.
Ahmadinejad's actions led to angry public attacks by clerics, parliamentarians and military commanders, who accused him of ignoring orders from the supreme leader.
Conservative opponents in parliament launched an "impeachment drive" against him, four websites with ties to Ahmadinejad reportedly were "filtered and blocked", and several people "said to be close" to the president and Mashaei (such as Abbas Amirifar and Mohammed Sharif Malekzadeh) were arrested on charges of being "magicians" and invoking djinns.
On 6 May 2011, it was reported that Ahmadinejad had been given an ultimatum to accept the leader's intervention or resign, and on 8 May, he "apparently bowed" to the reinstatement, welcoming back Moslehi to a cabinet meeting.
The events have been said to have "humiliated and weakened" Ahmadinejad, though the president denied that there had been any rift between the two, and according to the semiofficial Fars News Agency, he stated that his relationship with the supreme leader "is that of a father and a son."

In 2012, Khamenei ordered a halt to a parliamentary inquiry into Ahmadinejad's mishandling of the Iranian economy.
In 2016, Khamenei advised Mahmoud Ahmadinejad, his former ally with whom his relationship was strained after Ahmadinejad accused his son Mojtaba Khamenei of embezzling from the state treasury, to not run for president again.
Early in his presidency, Ahmadinejad was sometimes described as "enjoy[ing] the full backing" of the Supreme Leader Ali Khamenei, and even as being his "protege." In Ahmadinejad's 2005 inauguration the supreme leader allowed Ahmadinejad to kiss his hand and cheeks in what was called "a sign of closeness and loyalty," and after the 2009 election fully endorsed Ahmadinejad against protesters. However, as early as January 2008, signs of disagreement between the two men developed over domestic policies, and by the period of 2010–11 several sources detected a "growing rift" between them. The disagreement was described as centered on Esfandiar Rahim Mashaei, a top adviser and close confidant of Ahmadinejad and opponent of "greater involvement of clerics in politics", who was first vice president of Iran until being ordered to resign from the cabinet by the supreme leader.
In 2009, Ahmadinejad dismissed Intelligence Minister Gholam-Hossein Mohseni-Eje'i, an opponent of Mashaei. In April 2011, another Intelligence minister, Heydar Moslehi, resigned after being asked to by Ahmadinejad, but was reinstated by the supreme leader within hours. Ahmadinejad declined to officially back Moslehi's reinstatement for two weeks and in protest engaged in an "11-day walkout" of cabinet meetings, religious ceremonies, and other official functions. Ahmadinejad's actions led to angry public attacks by clerics, parliamentarians and military commanders, who accused him of ignoring orders from the supreme leader. Conservative opponents in parliament launched an "impeachment drive" against him, four websites with ties to Ahmadinejad reportedly were "filtered and blocked", and several people "said to be close" to the president and Mashaei (such as Abbas Amirifar and Mohammed Sharif Malekzadeh) were arrested on charges of being "magicians" and invoking djinns. On 6 May 2011, it was reported that Ahmadinejad had been given an ultimatum to accept the leader's intervention or resign, and on 8 May, he "apparently bowed" to the reinstatement, welcoming back Moslehi to a cabinet meeting. The events have been said to have "humiliated and weakened" Ahmadinejad, though the president denied that there had been any rift between the two, and according to the semiofficial Fars News Agency, he stated that his relationship with the supreme leader "is that of a father and a son."
In 2012, Khamenei ordered a halt to a parliamentary inquiry into Ahmadinejad's mishandling of the Iranian economy. In 2016, Khamenei advised Mahmoud Ahmadinejad, his former ally with whom his relationship was strained after Ahmadinejad accused his son Mojtaba Khamenei of embezzling from the state treasury, to not run for president again.
Mahmoud Ahmadinejad