As the kings of Castile endeavoured to strengthen monarchical power in the late medieval centuries, they encountered a stiff challenge from the nobility, who tried to use the institutions of government for their own interests. The struggle for power commenced during the reign of Alfonso X the Learned (1252-84), who is perhaps best known for the literary and scientific achievements under his direction by scholars whom he summoned to his court. His initial aim was to gain control of the Moroccan ports giving access to the Iberian Peninsula, but that provoked a revolt in 1264-66 by the Mudéjares of Andalusia and Murcia, abetted by the king of Granada. Elected Holy Roman emperor in 1257, Alfonso, for the next 17 years, engaged in a vain effort to counter a rival claimant and to secure papal acceptance. His expenditure of great sums of money on this enterprise and his innovations in taxation and legislation eventually brought about a grave challenge to his rule.
The pope in 1274 refused to recognize Alfonso's imperial claims, and the king's eldest son and heir, Fernando de la Cerda, died in 1275 while hastening to repel a Moroccan invasion. A dispute over the succession between the adherents of Fernando de la Cerda's son, Alfonso, and the king's second son, Sancho, ensued. Although the king recognized Sancho, their relationship deteriorated, in part because Alfonso X's ill health rendered him less able to carry out his duties and caused him to act arbitrarily. In 1282 an assembly of nobles, prelates, and townsmen transferred the responsibilities of government from the king to Sancho. While the Muslims continued to threaten the kingdom externally, Castile was torn apart by civil war until the king's death.
During the reign of Sancho IV (1284-95) domestic and foreign supporters of his nephew maintained a steady opposition. At the same time, Sancho had to defend the realm against another Muslim invasion from Morocco. Thus began a long struggle to control the Strait of Gibraltar and to close that invasion route.
In the late Middle Ages the Crown of Aragon experienced a confrontation between the monarchy and the nobility similar to that which occurred in neighbouring Castile. A critical stage in relations between the crown and the nobles was reached during the reign of Peter III the Great (1276-85), the heir to Aragon, Catalonia, and Valencia (the kingdom of Majorca fell to the share of his younger brother James).
Peter III's conquest of Sicily was the second major step in the Mediterranean expansion of Catalonia, and it also marked the beginning of a long international struggle with serious domestic complications. Although the papacy had awarded Naples and Sicily to Charles of Anjou, Peter's wife represented Hohenstaufen claims to them. Taking advantage of the rebellion against Charles's rule known as the Sicilian Vespers, Peter occupied Sicily in 1282. Pope Martin IV not only excommunicated and deposed Peter but also offered Aragon to a French prince. After the pope proclaimed a crusade, King Philip III of France led the crusading army against Peter but failed to achieve success. Thereafter the disposition of Sicily remained the chief concern of Peter's three sons.
Alfonso III (1285-91), who inherited the mainland dominions, and his younger brother James, who received Sicily, valiantly tried to overcome the formidable opposition of the pope, the king of France, and the house of Anjou. Alfonso seized Majorca because his uncle James had aided the French during their crusade against Aragon. Once again the Aragonese nobles challenged the king, forcing him in 1287 to permit the nobles to control the appointment of certain royal councillors.
Early in the 13th century Alfonso VIII of Castile and Alfonso IX of León founded the Universities of Palencia and Salamanca, respectively, for the study of theology, philosophy, and Roman and canon law. Although Palencia ceased instruction by the middle of the century, Salamanca eventually attained international renown. The appearance about 1200 of the first great epic in the Castilian tongue, The Poem of the Cid, signaled the beginning of the development of a significant vernacular literature. Although the literary production of Spanish authors was still limited, Rodrigo Jiménez de Rada, archbishop of Toledo (d. 1247), through his historical works, fixed the standard for Spanish historiography for centuries to come.