In response to threats from the Republic of Venice and the Kingdom of Naples, Ludovico Sforza the duke of Milan had invited France and Spain into Italy to protect Milan from her enemies. In answer to this request for aid, King Charles VIII of France came to Sforza's assistance by invading Italy in the first Italian Wars (1494–1498). However, in the first battle of that first Italian war—the battle of Fornovo on 6 July 1495—Ludovico Sforza suddenly and unexpectedly changed sides—thus, joining the Venetians and the Kingdom of Naples against the French and Spanish.
Charles VIII died on 7 April 1498 and was followed to the throne by Louis XII of France. Immediately, King Louis concluded an alliance with the Republic of Venice and obtained some Swiss mercenaries and invaded the Duchy of Milan under the condition that the Lombardian territories be split between Venice and France. Papal support was given for the campaign in exchange for Louis XII's military support for Cesare Borgia's Romagna campaigns. Ludovico Sforza, having also hired an army of Swiss mercenaries, returned to Milan only to find it occupied by Gian Giacomo Trivulzio, who had joined the French; Ludovico's army was soon scattered, and he himself imprisoned in France. Following the final overthrow of Sforza, the Duchy of Milan would serve, for the next twelve years, as a French stronghold and as a springboard for further French military adventures in Italy.
As the summer campaign season of the year 1500 neared, Louis XII became worried about the intentions of newly unified Spain to his west if he moved into Italy to the east. The Spanish monarchs Ferdinand and Isabella were known to be fearful of a new rapprochement between Louis XII and the Italian powers. They might invade France from the west, while Louis XII had his armies in Italy, and thus involve Louis in a war on two fronts. To avoid this prospect, Louis signed an agreement with Spain that divided the spoils of Naples between France and Spain when Naples was conquered. This was the Treaty of Granada signed on 11 November 1500.
The Treaty of Granada was a watershed document accepted by Pope Alexander VI. Spanish influence would grow and later haunt Louis and his successors to the throne of France.
In his claim to Milan, King Louis XII asserted a family inheritance to support his claim to the Duchy of Milan. However, in the case of Naples, Louis had no inheritance to claim. Instead, Louis XII's claim to Naples rested entirely on Charles VIII's claim and his temporary occupation of the Naples. This was called the "Angevin inheritance." The Angevin inheritance came to Charles VIII as early as 1481 and was the basis of Charles' military campaign against Naples in 1495. Louis XII claimed the Angevin inheritance only because he was the successor of Charles VIII to the throne of France. The present king of Naples, Frederick IV, claimed the throne of Naples upon the death of his nephew, Ferdinand II, in 1496. Ferdinand II was the son of Alfonso II of Naples. Alfonso II had abdicated the throne of Naples to Charles VIII in 1495. Thus, both Ferdinand and his uncle, Frederick IV, were considered illegitimate inheritors and usurpers of the Neapolitan title that rightly belonged to the king of France, now Louis XII.
Louis XII and Isabel & Fernando, monarchs of Spain, had agreed to these terms on 11 November 1500 in the Treaty of Granada, and Pope Alexander VI, nominal overlord of the Kingdom of Naples, approved this deal on 25 June 1501.
Pursuant to the Treaty of Granada, French and Spanish armies seized Naples on 2 August 1501. Although it was agreed that Louis XII should assume the throne of Naples, Louis and the monarchs of Spain soon quarreled over the division of the rest of the spoils. Soon war broke out again between France and Spain.
When the conflict broke out again in the second half of 1502, Don Gonzalo de Cordoba lacked numeric superiority, but was able to apply the lessons learned in 1495 against the Helvetic infantry; moreover, the Spanish tercios, accustomed to close combat after the Reconquista, redressed some of this imbalance. Cordoba avoided encounter with the enemy at first, hoping to lure the French into complacency. Later, the conflict became characterized by short skirmishes. During this campaign, a French knight, il La Motte, was captured by Spanish forces and later used as an hostage to declare his famous Challenge of Barletta on 13 February 1503. Chronic in-fighting between the Italian and French knights, as well as a better supply-line guaranteed by the Spanish navy, gave Cordoba the upper hand against the French, who suffered defeat at Cerignola on 28 April 1503 and Garigliano on 29 December 1503. Louis XII was forced to abandon Naples and, on 2 January 1504, left Naples to withdraw to Lombardy.