In 1499, Louis XII of France launched the Second Italian War, invading Lombardy and seizing the Duchy of Milan. He then reached an agreement with Ferdinand I of Spain to divide Naples. By 1502, combined French and Spanish forces had seized control of the Kingdom; disagreements about the terms of the partition led to a war between Louis and Ferdinand. By 1503, Louis, having been defeated at the Battle of Cerignola and Battle of Garigliano, was forced to withdraw from Naples, which was left under the control of the Spanish viceroy, Gonzalo Fernández de Córdoba. Meanwhile, Pope Alexander VI attempted to carve a Borgia state from the Romagna through the efforts of Cesare Borgia.