The Marinid dynasty (Arabic: المرينيون, romanized: al-Marīniyyūn) was a Sunni Muslim dynasty that controlled present-day Morocco from the mid-13th to the 15th century and intermittently controlled other parts of North Africa (Algeria and Tunisia) and of the southern Iberian Peninsula (Spain) around Gibraltar. They were a culturally Arabized dynasty of Berber origin. The dynasty takes its name from the Banu Marin (Arabic: بنو مرين; Berber languages: Ayt Mrin), the Zenata Berber tribe from which it originated.
After being at their service for a brief period, the Marinids waged war during the 13th century to overthrow the Almohads, who ruled the western Maghreb, eventually succeeding in 1269 with the capture of Marrakesh. 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 and made an attempt to gain a direct foothold on the European side of the Strait of Gibraltar. They were however defeated at the Battle of Río Salado in 1340 and finished after the Castilians took Algeciras in 1344, definitively expelling them from the Iberian Peninsula. Starting in the early 15th century, the Wattasid dynasty, a related ruling house, competed with the Marinid dynasty for control of the state and became de facto rulers 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.