During the 9th century, however, a range of new movements emerged on the basis of Shi'ite doctrines, which replaced Kharijism as the main idiom for opposition to established regimes. Zaydi imams had already established independent dynasties in the fringes of the Abbasid empire, in Tabaristan (864) and Yemen (897), but by the time of al-Muktafi's accession, the core regions of the Caliphate itself were menaced by the Qarmatians, a radical Isma'ili Shi'ite sect. The Qarmatians denounced mainstream Sunni Islam for practices they viewed as deviations from the true teachings of the religion, such as the Hajj and the worship of the Kaaba, as well as the dwelling in cities and the marginalization of the Bedouin. Consequently, the Qarmatians gained many adherents among the latter—although the Qarmatian leadership overwhelmingly came from the urban settlers—and began assaulting the neighbouring Muslim communities. Their missionary efforts soon spread: in 899, the Qarmatians seized Bahrayn, while another base was established in the area around Palmyra. From there the Qarmatians began launching raids against the Abbasid and Tulunid provinces of Syria. In 902, the Qarmatians defeated the increasingly feeble Tulunids and laid siege to Damascus. Although the city withstood the siege, the Qarmatians proceeded to ravage other Syrian towns. At the same time, a Kufan Isma'ili missionary, Abu Abdallah al-Shi'i, made contact with the Kutama Berbers. His proselytization efforts made rapid headway among them, and in 902, he began his attacks on the Aghlabid emirate of Ifriqiya. Its conquest was completed in 909, laying the foundations of the Fatimid Caliphate. In July 903, al-Muktafi decided to personally campaign against the Qarmatians, and left Baghdad for Raqqa at the head of the army. While al-Muktafi remained at Raqqa, actual command was given to the head of the department of the army (), Muhammad ibn Sulayman al-Katib. Other Abbasid forces, under Badr al-Hammami and al-Husayn ibn Hamdan, also operated against the Qarmatians, defeating them near Damascus in July, but also suffering a defeat near Aleppo the next month. Finally, on 29 November 903, near Hama, Muhammad ibn Sulayman came upon the main Qarmatian army and routed it, capturing or killing its main leaders and dispersing their troops. Al-Muktafi returned to Baghdad with the senior captives, who were thrown into prison. Muhammad ibn Sulayman remained at Raqqa to scour the countryside and round up the remaining rebels. He too then returned to Baghdad, which he entered in triumph on