It begins according to Ibn Khaldūn with the flight of Sulaymān Ibn ʿAbd Allāh al-Kāmil towards the Maghreb after the Battle of Fakhkh in 786, then its takeover of Tlemcen then in the hand of the Zenata, (in the northwest of present-day Algeria).