Ferdinand's father, Alphonso, finding his tenure of the throne uncertain on account of the approaching invasion of Charles VIII of France and the general dissatisfaction of his subjects, abdicated in Ferdinand's favour on 23 January 1495. The 24-year-old new king tried to resist, but the French troops had already occupied much of the northern territories of the kingdom. The Neapolitan troops on the Liri and Garigliano rivers were obliged to retreat when the fortresses of Capua and Gaeta fell. The treason of a party in Naples rendered it impossible to defend the city against the approach of Charles VIII, who entered Naples on 20 February 1495. In the capital, only Castel dell'Ovo resisted, defended by Alfonso d'Avalos. Ferdinand fled to the castle at Ischia with an escort of 14 galleys, together with the royal family, the general Innico d'Avalos and the poet Jacopo Sannazaro. The commander of the island fortress had already made an agreement with the French, and opposed the King's entrance. When the two met, Ferdinand killed the commander personally, and had his body thrown into the sea. Ferdinand later moved to Messina, where he joined his cousin Ferdinand II, King of Sicily and Spain. In the meantime, Pope Alexander VI, formed a coalition against Charles, made up of Emperor Maximilian, Venice, Milan and Spain. When the French king left Naples with most of his army, Ferdinand disembarked at Seminara in Calabria, forcing his way north to Naples. Blocked by French garrisons at Palmi, he decided to return to Naples by sea, and was again at Ischia on 7 July 1495. The same day he was again in Naples: the citizens, irritated by the terrible conduct of their French conquerors during the occupation of the city, received him back with enthusiasm. With the aid of the great Spanish general Gonzalo Fernández de Córdoba, Ferdinand was able to rid his state completely of its invaders shortly before his death. In August 1496, with the kingdom firmly back in his hands, Naples was able to celebrate Ferdinand's wedding to his 18-year-old half-aunt Joanna. Joanna was the late-born daughter of Ferdinand's grandfather Ferdinand I and his second wife, Joanna of Aragon. She was younger than Ferdinand, who was 27. After the wedding the royal couple decided to leave Naples and moved to Somma-Vesuvius. Here the king was struck with an illness and died within a few days, on 7 September 1496, a little over a year after his restoration. He was succeeded by his uncle Frederick, legitimate brother of his father, Alfonso II.