Abbas Milani examines Ahmadi's defiance towards a regime that created him:
Even after a week-long delay in acknowledging Khamenei's order [to fire his deputy], Ahmadinejad still did not fully carry it out. He wrote back a note--terse, angry and defiant in tone--declaring that Mashai had decided to resign his post (rather then being dismissed, as Khamenei had decreed). More incredible still, Ahmadinejad appointed Mashai to the important position of his own chief of staff and special advisor to the president--in brazen defiance of Khamenei and nearly the entire top clerical establishment of the regime. [...]
The events of the past few days reveal the June 12 electoral coup's chickens coming home to roost. The regime handed Ahmedinejad a landslide victory--and he wasted no time in exercising his power accordingly, even against those that manufactured his win. It seems that, like the rest of the nation, he sees the nearing end of Khamenei's days as an absolutist ruler, and is trying to establish an independent turf of his own.