Zayyanid capture of Fez

The Zayyanid capture of Fez took place in 1423 and was led by Abu Malik Abdulwahid, the ruler of Tlemcen. He succeeded in briefly installing his own client king on the Marinid throne in Fez, before being defeated the following year by the Hafsid sultan of Tunis.

Background
Abu Malik, the son of Abu Tashufin II, had ascended to the throne of the Kingdom of Tlemcen in 1411 thanks to the support of the Marinid ruler, Abu Sa'id III. After the latter's death, the Marinid kingdom (roughly present-day Morocco) fell into disarray as different claimants to the throne fought with each other, resulting in a four-year civil war. One of these claimants was a grandson of Abu Inan named Muhammad, who had taken refuge on the Iberian Peninsula.

During this chaos, the emir of Granada, Muhammad IX, attempted to gain his own foothold in the region by supporting Salah ibn Salah, the former Marinid governor of Ceuta prior to its capture by the Portuguese years earlier. Salah installed himself in Tangier and took control of a territory from there to Ksar el-Kebir, briefly paying tribute to Granada before becoming effectively independent.

Zayyanid campaign
Muhammad requested help from the Zayyanid sultan to take the throne. Abu Malik took this opportunity to turn against the Marinids and expand his own power. He led an army west, defeated Marinid forces, and captured the Marinid capital of Fez in 1423. He installed Muhammad on the Marinid throne as a client of Tlemcen who promised to pay him tribute.

Aftermath
Meanwhile, the Marinid governor of Salé, Abu Zakariya Yahya al-Wattasi, took charge of Abu Sa'id's only son, an infant, and proclaimed him sultan as Abd al-Haqq II, while ruling formally on his behalf. The Zayyanid victory also provoked the concern of the Hafsid ruler in Tunis, Abu Faris Abd al-Aziz II. To counteract Abu Malik's success, he provided support to another son of Abu Tashufin II, Abu Abdallah Muhammad IV, who had been in refuge at his court in Tunis. Abu Faris gave Abu Abdallah an army which advanced on Tlemcen, forcing Abu Malik to abandon the city and flee to Fez in April 1424.

By 1425, Abu Zakariya Yahya had made an alliance with Salah ibn Salah and sought the aid of the Hafsids. In late 1425, Abu Faris himself left Tunis and joined his army in Tlemcen. He proceeded west and captured Taza, on the road to Fez. Upon hearing this news, Fez surrendered to him and paid him a large tribute. The Marinid pretender, Muhammad, was deposed, while Abu Malik surrendered himself to Abu Faris and pledged him his support. By 1426, Abd al-Haqq II was installed as the formal Marinid sultan in Fez and as a vassal of the Hafsids. Abu Zakariya Yahya held effective power as his vizier, a situation which would last until 1457.

Abu Malik would return to the throne of Tlemcen in 1428, after securing his own support from the Hafsid sultan and using a Hafsid army to expel Abu Abdallah from Tlemcen. The latter fled to Dahra, gathered a new army, and defeated Abu Malik again in several battles, recapturing Tlemcen in 1430. He was defeated in turn a year later by the Hafsid sultan, who had him executed and installed a new client Zayyanid on the throne. The Zayyanids of Tlemcen continued to recognize the authority of the Hafsids until the end of the 15th century.