Ahmad al-Mansur was the longest-reigning sultan of the Saadian dynasty, whose capital was in Marrakesh in present-day Morocco. He came to power as a consequence of the crucial Battle of Ksar el-Kebir in northern Morocco in 1578. In that battle he had been part of the army of his brother Abd al-Malik, which successfully defeated a major Portuguese invasion force led by Sebastian I on behalf of Abd al-Malik's nephew, Muhammad Al-Mutawakkil, whom he had deposed two years earlier. Sebastian I, Al-Mutawakkil, and Abd al-Malik all died during the battle – with Abd-al-Malik possibly poisoned by one of his Turkish officers – which left Ahmad as the surviving victor of the battle and the new sultan on the Saadian throne. Drawing on the prestige of the victory, he took on the regnal title ("laqab") "al-Mansur".