In the 9th–14th centuries, the northern
Iranian regions of
Tabaristan,
Daylam and
Gilan, sandwiched between the
Caspian Sea and the
Alborz range, came under the rule of a number of
Alid dynasties, espousing the
Zaydi branch of
Shi'ism. The first and most powerful Zaydi emirate was established in
Tabaristan in 864 and lasted until 928. It was interrupted by
Samanid occupation in 900, but restored in 914 by another Alid branch. The second period of the Alid emirate was plagued by internal dissensions and power struggles between the two branches, and ended in the second conquest of the region by the Samanids in 928. Subsequently, some of the soldiers and generals of the Alavids joined the Samanids, among them the founder of the
Ziyarid dynasty,
Mardavij, and
Ali, Hassan and Ahmad, the sons of Buya and founders of the
Buyid dynasty.