On the last day of 1229, King James I of Aragon captured Palma after a three-month siege. The rest of Mallorca quickly followed. Menorca fell in 1232 and Ibiza in 1235. In 1236, James traded most of the islands to Peter I, Count of Urgell for Urgell, which he incorporated into his kingdom. Peter ruled from Palma, but after his death without issue in 1258, the islands reverted by the terms of the deal to the Crown of Aragon.
James died in 1276, having partitioned his domains between his sons in his will. The will created a new Kingdom of Mallorca from the Balearic Islands and the mainland counties of Roussillon or Montpellier, which was left to his son James II. However, the terms of the will specified that the new kingdom be a vassal state to the Crown of Aragon, which was left to his older brother Peter. Chafing under the vassalage, James joined forces with the Pope Martin IV and Philip III of France against his brother in the Aragonese Crusade, leading to a 10-year Aragonese occupation before the islands were restored in the 1295 Treaty of Anagni. The tension between the kingdoms continued through the generations until James’ grandson James III was killed by the invading army of Peter’s grandson Peter IV at the 1349 Battle of Llucmajor. The Balearic Islands were then incorporated directly into the Crown of Aragon.