The dynasty's rise to power started in 1510 when Muhammad al-Qa'im was declared leader of the tribes of the Sous valley in their resistance against the Portuguese who occupied Agadir and other coastal cities. Al-Qai'm's son, Ahmad al-Araj, secured control of Marrakesh by 1525 and, after a period of rivalry, his brother Muhammad al-Shaykh captured Agadir from the Portuguese and eventually captured Fez from the Wattasids, securing control over nearly all of Morocco. After Muhammad al-Shaykh's assassination by the Ottomans in 1557 his son Abdallah al-Ghalib enjoyed a relatively peaceful reign. His successors, however, fought with each other, culminating in the 1578 Battle of Ksar el-Kebir (or "Battle of the Three Kings"), where a Portuguese military intervention on behalf of Muhammad II al-Mutawakkil was thoroughly defeated by Saadian forces. In the wake of this victory, Ahmad al-Mansur became sultan and presided over the apogee of Saadian power. In the later half of his reign he launched a successful invasion of the Songhai Empire, resulting in the establishment of a Pashalik centered on Timbuktu. After Al-Mansur's death in 1603, however, his sons fought a long internecine conflict for succession which divided the country and undermined the dynasty's power and prestige. While the Saadian realm was reunified at the end of the conflict in 1627, new factions in the region rose to challenge Saadian authority. The last Saadian sultan, Ahmad al-Abbas, was assassinated in 1659, bringing the dynasty to an end. Moulay al-Rashid later conquered Marrakesh in 1668 and led the Alaouite dynasty to power over Morocco.