 In 1494, Charles VIII of France invaded Italy and expelled Alfonso II, who was Ferdinand's first cousin once removed and step nephew, from the throne of Naples.Ferdinand allied with various Italian princes and with Emperor Maximilian I to expel the French by 1496 and install Alfonso's son, Ferdinand II, on the Neapolitan throne.In 1501, following Ferdinand II's death and accession of his uncle Frederick, Ferdinand signed an agreement with Charles VIII's successor, Louis XII, who had just successfully asserted his claims to the Duchy of Milan, to partition Naples between them, with Campania and the Abruzzi, including Naples itself, going to the French and Ferdinand taking Apulia and Calabria.