After his death, Abu Bakr, the prophet’s father-in-law, was chosen to be his successor. Although most tribes acknowledged his leadership, some tried to server their political and religious ties with Medina, hence Abu Bakr launched the Ridda wars to consolidate the rule of the believers. In addition to that, the believers launched several campaigns against other tribes and by 634 the entire Arabian peninsula was under their control as an Arabian state. Moreover the Sasanians were defeated in 637 and Iraq was under the control of the believers who penetrated into Khuzestan and Azerbaijan. The first civil war, from 656 to 661, occurred due to a struggle for leadership within the community of believers between Ali, the prophet’s cousin and son-in-law and Muwiyah of the Umayyad clan. It ended with the assassination of Ali by a Kharijite assassin and ultimately Muwiyah became the next caliph initiating the Umayyad caliphate which lasted from 661 to 750. In 680, during the second civil war, the Umayyad troops massacred Ali’s son and his family, an act that the Shiites recognized as martyrdom. Furthermore, the martyrdom forced them to view themselves as a distinct political party in the Islamic community.
In the 750s the Umayyad dynasty was overthrown by the Abbasids, who were in power from 750 to 1258. They founded a new capital in Baghdad and further expanded the Islamic community. In north Africa they dislodged the Byzantine outposts while others invaded Atlantic Morocco. In 756 several Umayyad princes were murdered but one escaped into north Africa and later invaded Spain which became an independent state under Umayyad rule. In the 9th century, the Abbasid governors of Tunisia, the Aghlabids, raided Sicily and established a Muslim political presence. The Abbasid caliphate was slowly losing its political control of their states. The Abbasid governorship was given to military commanders and the military eventually proved too powerful to control as it assassinated a caliph and caused the making and unmaking of four caliphs in Samara. Moreover the caliphate neglected control outside Iraq due to lack of resources hence many states became virtually independent of the caliphate reducing their political presence.