Islamic rule in Tripolitania and Cyrenaica began as early as the 7th century. With tenuous Byzantine control over Libya restricted to a few poorly defended coastal strongholds, the Arab invaders who first crossed into Pentapolis, Cyrenaica in September 642 encountered little resistance. Under the command of Amr ibn al-A'as, the armies of Islam conquered Cyrenaica, renaming the Pentapolis, Barqa.
See main article: Islamic conquest of North Africa. It is recorded by Ibn Abd al-Hakam that during the siege of Tripoli by Amr ibn al-As, seven of his soldiers from the clan of Madhlij, sub branch of Kinana, unintentionally found a section on the western side of Tripoli beach that are not walled during their hunting routine. those seven soldiers then manage to infiltrate through this way without detected by the city guards, then manage to do incite riot within the city while shouting Takbir, causing the confused Byzantine garrison soldiers thought the Muslim forces were already inside in the city and fled towards their ship leaving Tripoli, thus, allowing Amr to subdue the city easily.[1] Later, the Muslim forces besieged Barqa (Cyrenaica) for about three years to no avail. Then Khalid ibn al-Walid, who previously involved in the conquest of Oxyrhynchus, offered a radical plan to erect catapult which filled by cotton sacks. Then as the night came and the city guard slept, Khalid ordered his best warriors such as Zubayr ibn al-Awwam, his son Abdullah, Abdul-Rahman ibn Abi Bakr, Fadl ibn Abbas, Abu Mas'ud al-Badri, and Abd al-Razzaq to step into the catapult platform which filled by cotton sacks. The catapult launched them one by one to the top of the wall and allowed these warriors to enter the city, opening the gates and killing the guards, thus allowing the Muslim forces to enter and capturing the city.[2]
From Barqa, Uqba bin Nafi led a campaign against Fezzan, marching to Zaweela, the capital of Fezzan. No resistance was offered, and the entire district submitted to the Muslims, agreeing to pay the Jizya (tax on non-Muslims). A clause was further inserted in the peace treaty that part of the Jizya coming from the district was to be spent on the poor of the area.
In 647 an army of 40,000 Arabs, led by ‘Abdu’llah ibn Sa‘ad, the foster-brother of Caliph Uthman ibn Affan, penetrated further into western Libya. Tripoli was taken from the Byzantines, followed by Sufetula, a city 150 miles south of Carthage, where the Exarch Gregory, was killed. The campaign lasted fifteen months, after which Abdallah's force returned to Egypt after Gregory's successor Gennadius promised them an annual tribute of some 330,000 nomismata. Gennadius also sent the usual surplus of revenues over expenditures to Constantinople, but otherwise administered Africa as he liked. The new Exarch's greatest source of strength was from the Libya tribes: Nasamones, Asbytae, Macae Garamantes and others. When Gennadius refused to pay the additional sums demanded from Constantinople, he was beheaded.
Following the revolt Gennadius fled to Damascus and asked for aid from Muawiyah, to whom he had paid tribute for years. The caliph sent a sizable force with Gennadius to invade Africa in 665. Even though the deposed exarch died after reaching Alexandria, the Arabs marched on. From Sicily the Byzantines dispatched an army to reinforce Africa, but its commander, Nicephorus the Patrician lost a battle with the Arabs and reembarked. Uqba ibn Nafi and Abu Muhajir al Dinar did much to strengthen Umayyad imperial rule. Most local Berbers converted slowly to Islam in the following centuries under Berber Almohad rule, long after the fall of the Umayyad Arab empire. The social and linguistic character of Libya remained overwhelmingly Berber for many more centuries.
In 750 the Abbasid dynasty overthrew the Umayyad caliph and shifted the capital to Baghdad, with emirs retaining nominal control over the Libyan coast on behalf of the far-distant caliph. In 800 Caliph Harun ar-Rashid appointed Ibrahim ibn al-Aghlab as his governor. The Aghlabids dynasty effectively became independent of the Baghdad caliphs, who continued to retain spiritual authority. The Aghlabid emirs took their custodianship of Libya seriously, repairing Roman irrigation systems, restoring order and bringing a measure of prosperity to the region.
In the last decade of the 9th century, the Ismailis launched an assault on the Sunni Aghlabids. The Ismaili spiritual leader or imam, Abdallah al Mahdibillah of Syria, was installed as the imam of much of the Maghreb, including Tripolitania. The Amazigh of Libya eventually came to accept the imam as the Mahdi (Promised One).
The Isma'ili Muslim Fatimid Caliphate conquered Ikhshidid Egypt in 972 and set up their caliphate in a newly-created city, Cairo. The difficulty of maintaining control of Libya plagued the Fatimids, as it had almost every other authority preceding them. At the beginning of the 11th century, Buluggin ibn Ziri was installed as the Fatimid governor. It was also in this time that the Cyrenaica became a basis for pirates who often acted as privateers for the Fatimids.[3] Finally, under Al-Mu'izz ibn Badis, the Zirids split off the Fatimid caliphate in 1045 and in 1051/52, the emir of Barca, Jabbara ibn Mukhtar, acknowledge the suzerainty of the Al-Mu'izz.
Tripoli was pillaged in 1146 by the Italo-Normans. In 1158, the supporters of the Almohad Caliphate arrived in Tripoli from Morocco and established their authority. An Almohad emir, Muhammad bin Abu Hafs, ruled Libya from 1207 to 1221 and established the Hafsid dynasty.