During the Abbasid Caliphate, the region was taken over by the Qarmatians, a Shi'ite group of the Isma'ili branch, around 899 AD. The Qarmatians attacked Makkah and Madinah and held the Black Stone to ransom in Ahsa in 920 AD. The region was ruled by the Qaramatians until 976 AD, when after losing to the Abbasids, they were reduced to the status of a local power. After Bahrain and Qatif seceded from Qarmatian rule around 1058 AD, they retreated to the Ahsa Oasis, to which Abdullah bin Ali Al Uyuni laid siege and invaded in 1076 AD, ending the rule of Qarmatians in Ahsa and founding the Uyunid Emirate.