Answer
Moulay Ismail Ibn Sharif, the founder of the Moroccan Alaouite dynasty, suffered a major military defeat at the Battle of Moulouya in 1689. The Moroccan army, led by Ismail himself, was outnumbered and outgunned by the Algerian army, led by the Bey of Algiers, Muhammad ben Abdallah. The Moroccans were defeated and Ismail was forced to retreat back to his capital at Meknes.