The Capture of Fez occurred in 1576 at the Moroccan city of Fez, when an Ottoman Empire force from Algiers supported Abd al-Malek in gaining the throne of Morocco against his nephew and rival claimant Mulay Muhammed. About 10,000 Ottoman soldiers participated in the campaign. This campaign followed a short-lived Ottoman capture of Fez in 1554.
Abd al-Malek won over his rival at the battle of ar-Rukn, also er-Roken. Mulay Muhammed fled to Marrakesh and would continue resisting Abd al-Malek for a long time.
Abd al-Malek entered Fez victoriously in March 1576.
Abd al-Malek recognized the Ottoman sultan Murad III as Caliph, and reorganized his army along Ottoman lines and adopted Ottoman customs, but negotiated for the Ottoman troops to leave his country, in exchange for a large payment in gold.
Meanwhile, Mulay Muhammed fled to Spain and then Portugal, when Sebastian of Portugal promised to help him regain his throne. This led to an expedition and the Battle of Ksar El Kebir in 1578,also known as the Battle of Three Kings which was a considerable defeat for the Portuguese and having lost their childless monarch Portugal passed into the hands of Spanish throne. Abdel Malik was probably poisoned and it was Abdel Malik's younger brother Ahmad Al-Mansour who assumed control of the Saadian state of Morocco.
These events left the Ottomans in a very strong position in the Maghreb, posing a direct threat to the Spanish heartland.