in northern Morocco until the Umayyads finally ended their rule definitively in 985. The Umayyads in turn kept control over northern Morocco until their caliphate's collapse in the early 11th century. Following this, Morocco was dominated by various Zenata Berber tribes. Until the rise of the Sanhaja Almoravids later in the century, the Maghrawa controlled Fes, Sijilmasa and Aghmat while the Banu Ifran ruled over Tlemcen, Salé (Chellah), and the Tadla region. 13th-16th centuries In the 13th century the Banu Marin (), a Zenata tribe, rose to power in Morocco. Starting in 1245 they began overthrowing the Almohads which had controlled the region. At the height of their power in the mid-14th century, during the reigns of Abu al-Hasan and his son Abu Inan, the Marinid dynasty briefly held sway over most of the Maghreb including large parts of modern-day Algeria and Tunisia. They supported the Emirate of Granada in al-Andalus in the 13th and 14th centuries; an attempt to gain a direct foothold on the European side of the Strait of Gibraltar was however defeated at the Battle of Río Salado in 1340 and finished after the Castilians took Algeciras from the Marinids in 1344, definitively expelling them from the Iberian Peninsula. In contrast to their predecessors, the Marinids sponsored Maliki Sunnism as the official religion and made Fez their capital. Under their rule, Fez enjoyed a relative golden age. The Marinids also pioneered the construction of madrasas across the country which promoted the education of Maliki ulama, although Sufi sheikhs increasingly predominated in the countryside. Starting in the early 15th century the Wattasid dynasty, a related ruling house, competed with the Marinid dynasty for control of their state and became de facto rulers of Morocco between 1420 and 1459 while officially acting as regents or viziers. In 1465 the last Marinid sultan, Abd al-Haqq II, was finally overthrown and killed by a revolt in Fez, which led to the establishment of direct Wattasid rule over most of Morocco. The Wattasid sultans in turn lasted until the mid-16th century, when they were finally overthrown by the Saadians, who inaugurated the beginning of Arab Sharifian rule over Morocco (which continues under the present-day Alaouite dynasty). Meanwhile, around the same time as the Marinids, the Zenata Zayyanid dynasty (also known as the Abd al-Wadids) ruled over the Kingdom of Tlemcen in northwestern Algeria, centered on Tlemcen. The territory stretched from Tlemcen