The Fatimid Dynasty formed in Ifriqiya in 909, and ruled over varying areas of the Maghreb, Egypt and the Levant until 1171. The Buyid dynasty emerged in Daylaman, north of Iran, about 930 and then ruled over central and western parts of Iran and Iraq until 1048. In Yemen, Imams of various dynasties usually of the Zaidi sect established a theocratic political structure that survived from 897 until 1962.