History of Islamic Tripolitania and Cyrenaica

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.
Islamic conquest.
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.
Internal struggles.
In 750 the Abbasid dynasty overthrew the Ummayad 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).
Fatamid dynasty.
The Shiite Fatimid dynasty conquered Misr (Egypt) in 972 and set up their caliphate in 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, Bulukkin ibn Ziri was installed as the Fatimid governor but he quickly returned Libya to orthodox Sunni Islam and swore allegiance to the Abbasid caliphs in Baghdad. The Fatimid anger at what they considered a gross betrayal profoundly altered the fabric and makeup of Libyan society. Two tribes from the Arabian Peninsula, the Banu Hilal and the Banu Sulaym, were co-opted into migrating to the Meghreb. The Banu Sulaym settled in Libya, particularly in Cyrenaica, while the Bani Hilal spread across North Africa. The Amazigh tribespeople were displaced from their traditional lands, their farmland converted to pasture and the new settlers cemented the cultural and linguistic Arabisation of the region.
Tripoli was pillaged in 1146 by the Normans of Sicily. In 1158, the supporters of the Almohad dynasty 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, which outlived the Almohads. The Hafsids ruled Tripoli for nearly 300 years. There was significant trade with the city-states of Europe and Hafsid rulers encouraged art, literature and architecture, and gave scholarship priority. In 1321 the Beni Ammar established an independent dynasty there, which lasted (with an interval, 1354–1369, during which two sovereigns of the Beni Mekki reigned) until 1401, when Tripoli was reconquered by Tunis.
Meanwhile, in the Fezzan in the 13th century, King Danama of Kanem (near Lake Chad) annexed territories as far north as the Al-Jufra oases. His Toubou viceroy founded the autonomous Bani Nasr dynasty, which ruled the Fezzan until the 14th century. They were followed by the theocratic kingdoms of Kharijite sectarians, including the Bani Khattab in the Fezzan. In the early 16th century, the Libyan Sahara fell under the control of Muhammad al-Fazi from Morocco who, early in the 16th century, founded the Awlad Suleiman dynasty in Murzuq.