Mazagan Ambush

In 1640, the Moroccans, led by Sidi al-Ayachi ambushed a Portuguese force from Mazagan, successfully killing most of them, including their commander.

Context
According to Ahmad ibn Khalid an-Nasiri, the city of Azemmour had signed a peace treaty with Mazagan at a time of political turmoil in Morocco. The captain of Mazagan ordered Azemmour to bring their own men for a duel between them. The captain saw the duel between a Portuguese and a Moroccan, until the Portuguese knight won the duel and killed the Moroccan. When the Moroccans saw this, they informed them that this would break the treaty. The captain began taunting them, and the leader of Azemmour then informed Sidi al-Ayachi about this incident. Ayachi then launched his attack on Mazagan.

However, according to Portuguese sources, a group of Moroccans came to Mazagan in April and told the captain, Dom Francisco de Mascarenhas, that the Moroccan sultan, Muhammad ibn Sharif, asked the Portuguese for some aid against his enemies, to which he agreed, though his commanders warned him of such an act. Francisco would leave Mazagan on April 11.

Battle
When al-Ayachi arrived in Mazagan, he found some members of the Oulad Abi Aziz tribe escaping and going to Mazagan because they were allied with the Portuguese. The captain of the fort then marched out with a force of 140 knights, and al-Ayachi stationed himself in a forest nearby the town. When the captain arrived in the forest, al-Ayachi cut off their escape route and encircled the Portuguese with a force of 4,000 infantry and cavalry. When the captain saw this dangerous situation, he asked his commanders what must be done, and they told him to fight until death. The Moroccans managed to wipe out the force. The Portuguese casualties were all but 27 killed, or 132 killed and 5 captured. Only two watchmen and a servant came out alive from the battle. The remaining prisoners were taken to Salé until they were ransomed by John IV of Portugal.