Islam has been the official religion and part of the governments of Iran since the Islamic conquest of Iran circa 640 AD. It took another few hundred years for Shi'a Islam to gather and become a religious and political power in Iran. Although Shi'as have lived in Iran since the earliest days of Islam, and there had been Shi'a dynasties in parts of Iran during the 10th and 11th centuries, according to Mortaza Motahhari the majority of Iranian scholars and masses remained Sunni till the time of the Safavids.
Today Islam is the religion of 98% of Iranians of which approximately 89% are Shi'a - almost all of whom are Twelvers. The next largest Shi'a group are the Nizari Ismailism Shi'a, sometimes called Seveners, some of whom fled Iran to South Asia, especially Mumbai, in the 1840s after a failed coup against the Shah of the Qajar dynasty. Many still remain scattered throughout Iran,The Shi'a groups have distinctions between Fiver, Sevener and Twelver, derived from their belief in how many divinely ordained leaders there were who are descendants of the Islamic prophet Muhammad through his daughter Fatimah and his son-in-law ‘Alī. These Imams are considered the best source of knowledge about the Qur'an and Islam, the most trusted carriers and protectors of Muḥammad's Sunnah (habit or usual practice) and the most worthy of emulation. In addition to the lineage of Imams, Twelvers have their preferred hadith collections - The Four Books - which are narrations regarded by Muslims as important tools for understanding the Quran and in matters of jurisprudence. For Twelvers the lineage of Imams are known as the Twelve Imāms. Of these Imams, only one is buried in Iran - at the Imam Reza shrine, for Ali ar-Ridha who lived from 765 - 818 AD, before any Shi'a dynasties arose in Iran. The last Imam recognized by Twelvers, Muhammad al-Mahdi, was born in 868 AD as the Alavids spread their rule in Iran while in conflict with Al-Mu'tamid, the Abbasid Caliph at the time. Several Imams are buried in Iraq, as sites of pilgrimage, and the rest are in Saudi Arabia. In addition two of the Five Martyrs of Shia Islam have connections to Iran - Shahid Thani (1506–1558) lived in Iran later in life, and Qazi Nurullah Shustari (1549–1610) was born in Iran. The predominant school of theology, practice, and jurisprudence (Madh'hab) in Shi'a Islam is Jafari established by Ja'far as-Sadiq.
Sunni Muslims are the second largest religious group in Iran.it came to rule in Iran after the period Sunni were distinguished from Shi'a through the Ghaznavids from 975 AD, followed by the Great Seljuq Empire and the Khwārazm-Shāh dynasty until the Mongol invasion of Iran.
About 9%of the Iranian population are Sunni Muslims - mostly Kurds in the northwest, Arabs and Balochs in the southwest and southeast, and a smaller number of Pashtuns and Turkmens in the northeast.
The predominant school of theology and jurisprudence (Madh'hab) among Sunnis in Iran is Hanafi, established by Abu Hanifa an-Nu‘man.
The Safavid sufi order, originates during the Safavid period. A later order in Persia is the Chishti. The Nimatullahi are the largest Shi'i Sufi order active throughout Iran and there is the Naqshbandi, a Sunni order active in the Kurdish regions of Iran. The Oveyssi-Shahmaghsoudi order is the largest Iranian Sufi order which currently operates outside Iran.
Famous Sufis include al-Farabi, al-Ghazali, Jalāl-ad-Dīn Rūmī and Hafiz. Rumi's two major works, Dīwān-e Šams and Maṭnawīye Ma'nawī, are considered by some to be the greatest works of Sufi mysticism and literature.