Cesare Borgia, who was facing the hostility of Ferdinand II of Aragon, was betrayed while in Naples by Gonzalo Fernández de Córdoba, a man he had considered his ally, and imprisoned there, while his lands were retaken by the Papacy. In 1504 he was transferred to Spain and imprisoned first in the Castle of Chinchilla de Montearagón in La Mancha, but after an attempted escape he was moved north to the Castle of La Mota, Medina del Campo, near Segovia. He did manage to escape from the Castle of La Mota with assistance, and after running across Santander, Durango and Gipuzkoa, he arrived in Pamplona on 3 December 1506, and was much welcomed by King John III of Navarre, who was missing an experienced military commander, ahead of the feared Castilian invasion.