Part One: The rising star of the La Cerda House
1. The civil war (1296-1299)
When Sancho IV of Castille died in 1295, his son Fernando IV was crowned king, several princes disputed this claim because his parents' marriage did not have the necessary papal dispensation for two reasons: First, they had a distant blood relation (Maria de Molina was the aunt of her husband), and second, Sancho had been betrothed as an infant to a rich Catalan heiress named Guillerma Montcada.
Juan of Castille, a brother of Sancho IV, claimed the throne for himself, but he was not alone in that, as the Infantes de la Cerda, Alfonso and Fernando, son of Fernando de la Cerda, the elder son of Alfonso X and brother of Sancho IV, added their claim to the Crown.
Alfonso X's eldest son, Fernando, died in 1275 at the Battle of Écija against the Moroccan and Granadan invasion armies, leaving two infant sons. Alfonso's second son, Sancho, claimed to be the new heir basing his claim on an old Castilian custom, that of proximity of blood and agnatic seniority. Alfonso X preferred to leave the throne to his grandsons, but Sancho had the support of the nobility. A bitter civil war broke out resulting in Alfonso's being forced in 1282 to accept Sancho as his heir instead of his young grandsons, even if Alfonso, in his lat will, excluded Sancho from the succession.
Then, on 1296, Alfonso and Fernando came back, with a vengeance and with the support of the kingdom of Aragon, claiming, rightfully, that Fernando IV was a bastard. Only the iron will of María de Molina, the mother of Fernando IV, kept their enemies at bay. Their luck changed in 1297, when she managed to win to their side king Doinis of Portugal, who changed sides and supported Fernando IV. However, this was achieved by returning to the Portugese crown the lands that Dionis had lost when he had been defeated by Alfonso X.
When this was known, many Castillian noblemen were dismayed at this and deserted Fernando (1). The private war between the De Haro (loyalist) and the De Lara (supporters of Alfonso) became mixed with the general strife and the kigndom felt into chaos, which made even more noblemen to distrust the king. Then Leon recognized Juan of Castille, the uncle of Fernando IV, as its King, and Juan recognized Alfonso as the true king of Castille. It seemed that Fernando IV was finished.
The Aragonese forceshad conquered Murcia in 1296. Then, Fernando IV, seeing his fortunes fading amidst the chaos and the desertions of his noblemen, decided to play a wild card and mustered his loyal troops to attack Jaime II de Aragon, but he was defeated and killed in the battle of Orihuela (May 1299).
Thus, Alfonso de la Cerda became Alfonso XI of Castille.
(1) Here you have the POD.