Prior to Islam, the inhabitants of Qatar and Bahrain practiced Arabian paganism, worshipping idols. Islam swept the entire Arabian region in the 7th century. Muhammad sent his first envoy Al-Ala'a Al-Hadrami to Munzir ibn Sawa Al Tamimi, the ruler of the historical region of Bahrain, which extended the coast from Kuwait to the south of Qatar including Al-Hasa, Qatif, and the Bahrain Islands, in the year 628 AD, inviting him to Islam. Munzir announced his conversion to Islam and all the Arab inhabitants of Bahrain and Qatar including some Persians living in Qatar also became Muslim, heralding the beginning of the Islamic era in Bahrain. The Khamis Mosque is believed to be the oldest mosque in Bahrain, with its origin dating back to the reign of Caliph Umar II.
The Ismaili Shia sect known at the Qarmatians seized Bahrain in 899 CE, making it their stronghold and base of operations. They raided Baghdad and in 930 sacked Mecca and Medina, desecrating the Zamzam Well with the bodies of Hajj pilgrim and taking the Black Stone with them back to Bahrain where it remained for twenty years. The Qarmatians were eventually defeated by their Ismaili counterparts, the Abbasids in 976 and afterwards their power waned.
The defeat of the Qarmatian state saw the gradual wane of their revolutionary brand of Ismaili Islam. Instead, under a process encouraged by Sunni rulers over the next four hundred years, Twelver Shia Islam became entrenched. According to historian Juan Cole, Sunnis favoured the quietist Twelver branch of Shi'ism over the Qarmatians and promoted its development in Bahrain. In the 13th Century, there arose what was termed the 'Bahrain School', which integrated themes of philosophy and mysticism into orthodox Twelver practise. The school produced theologians such as Sheikh Kamal al-Din Ibn Sa’adah al Bahrani (d. 1242), Sheikh Jamal al-Din ‘Ali ---
ibn Sulayman al-Bahrani (d. 1271), and perhaps most famously Sheikh Maitham Al Bahrani (d. 1280).