From The Doctrine of Mahdism:
According to Shi’ite tradition, the Twelve Imams, descendants of the Prophet Muhammad’s cousin and son-in-law Ali Ibn Abi Talib, were endowed with divine qualities that enabled them to lead the Shi’ite believers and to function as Allah’s emissaries on earth. However, when the Twelfth Imam, Muhammad Al-Mahdi, disappeared in 941 CE, his connection with the Shi’ite believers was severed, and since then, the Shi’ites are commanded to await his return at any time.
Immediately upon assuming the Iranian presidency, Ahmadinejad began to assert his belief in the imminent return of the Mahdi as the basis for his political activities. Despite the traditional belief that no one can foresee the hour of the Mahdi’s return, Ahmadinejad frequently stated that his coming was nigh, and even gave a more specific prediction. During a meeting with the foreign minister of an Islamic country, he said that the crisis in Iran “presaged the coming of the Hidden Imam, who would appear within the next two years.”
The messianic doctrine of Mahdism is also manifest in Iranian foreign policy, especially in its attitude toward the Western superpowers and toward the nuclear program. Ayatollah Mesbah-e Yazdi, mentor to Ahmadinejad, expressed this approach in an October 11, 2006 speech: “The greatest obligation of those awaiting the appearance of the Mahdi is fighting heresy and global arrogance [i.e., the West, primarily the U.S.].” Ahmadinejad and his close circle do not avoid confronting the West, since they consider this struggle to be one of the ways to prepare the ground for the return of the Mahdi.