In the minority of Ferdinand IV (1295-1312) new efforts were made in favour of Alfonso de la Cerda, but in 1304 he renounced all claims to any portion of the Crown of Castile. Although the king seized Gibraltar in 1309, the Muslims regained possession a quarter century later. The minority of Alfonso XI (1312-50) witnessed new disorders, but when Alfonso reached adult age he brutally crushed his enemies among the nobility. Aided by his Christian neighbours, he gained a great triumph over the allied Islamic forces from Granada and Morocco at the Salado River in 1340 and thus ended once and for all Moroccan attempts to establish a base in Spain. He captured Algeciras four years later, but he was unable to take the nearby fortress of Gibraltar because, like so many other thousands, he fell victim to the Black Death.
During the reign of Peter I the Cruel (1350-69) the monarchy and the nobility again came into violent conflict. Challenging the king's right to rule, his half brother, Henry of Trastámara, an illegitimate son of Alfonso XI, appealed to France for support. Backed by a mercenary army commanded by the Frenchman Bertrand du Guesclin, Henry was able to eject Peter from the kingdom in 1366. In order to recover his throne, the king enlisted the help of Edward, Prince of Wales, and a combined Anglo-Castilian army defeated Henry of Trastámara at Nájera in 1367. After Edward's withdrawal, however, Henry and du Guesclin defeated and killed Peter at Montiel in 1369.
As the first of the Trastámara dynasty, Henry II (1369-79) had to maintain his rights to the throne against his peninsular neighbours and domestic enemies. He eventually overcame his opponents and was even able to assist his French allies by providing a fleet to attack English shipping. As an ally of France, Henry's son John I (1379-90) acknowledged the Avignonese pope during the Great Western Schism. The aspirations of the Trastámara family to acquire the other peninsular kingdoms were first manifested when John claimed Portugal by right of marriage. His invasion in 1385 roused the Portuguese national spirit, and he suffered a grievous defeat at Aljubarrota. Then John of Gaunt, Duke of Lancaster, claiming the Castilian throne as the husband of Peter the Cruel's daughter, landed in Galicia in 1386. Though aided by the Portuguese, he was unsuccessful and came to terms in 1388. The marriage of his daughter Catharine to Henry III, the oldest son of John I, put an end to hostility between the two branches of the Castilian royal family.
After succeeding his brother as king of Aragon, James II (1291-1327) tried to secure an unchallenged title to that kingdom by yielding his rights to Sicily in 1295 and returning Majorca to his uncle James. Pope Boniface VIII awarded Sardinia to James II as compensation. In 1302 the pope reluctantly agreed to accept the third brother, Frederick, who had been proclaimed as king of Sicily. The Catalan Company, a mercenary troop idled by the end of the Sicilian wars, transferred its activities to the Byzantine Empire and in 1311 gained dominion over the duchy of Athens. Although neither Sicily nor Athens came under the direct rule of the king of Aragon, they remained bastions of Catalan influence and power in the Mediterranean.
James II, after securing a favourable alteration of his frontier with Murcia, occupied Sardinia in 1325. As Genoa disputed Aragonese rights there, his successors, Alfonso IV (1327-36) and Peter IV the Ceremonious (1336-87), had to wage a series of wars on that account. Accusing his cousin, the king of Majorca, of disloyalty, Peter IV annexed Majorca permanently to the Crown of Aragon in 1343. Peter provoked a constitutional crisis in 1347 when he named his daughter as heir to the throne rather than his brother, the Count de Urgel, who argued that women were excluded from the succession. The Aragonese union, which had been relatively inactive in the previous reign, again confronted the king and compelled him to confirm the privileges granted by his predecessors. The Valencian nobility also organized a union and exacted similar concessions. The devastation caused by the Black Death and the royalist victory over the Aragonese union at Epila in 1348 enabled Peter to dissolve the union and to tear up its privileges. The union never again threatened the crown.
After mid-century, Peter I of Castile invaded the Crown of Aragon, prompting Peter IV to back Henry of Trastámara's claims to the Castilian throne, but Henry subsequently refused to reward him with any territorial concessions. That disappointment was offset to some extent by the reincorporation of Sicily into the dominions of the Crown of Aragon in 1377. Peter IV remained neutral during the Great Western Schism, but his son John I (1387-95) acknowledged the pope of Avignon.
The cultural integration of Castile into western Europe was now complete. The development of Castilian as a literary language owed much to Alfonso X, whose stimulus to learning has been described as having prompted an intellectual renaissance. Under his patronage both the General estoria (General History) and the Estoria de Espanna ("History of Spain") were written; astronomical tables were arranged, and translations of Arabic scientific works were undertaken; and the Siete Partidas was compiled. The Cantigas de Santa María ("Songs to the Virgin") is a collection of more than 400 poems written in Galician, a language considered appropriate for lyric poetry; the poems are generally assumed to be the work of Alfonso himself, and many of them constitute a royal autobiography. Alfonso's nephew, Juan Manuel (d. 1348), authored many works, including El Conde Lucanor o el libro de Patronio (Count Lucanor or the Book of Patronius, a collection of Oriental fables). Juan Ruiz, the Archpriest of Hita (d. c. 1350) and one of the great medieval poets, took a satirical look at love; in his Libro de buen amor ( Book of Good Love) he interspersed ribald and comic poems of love with beautiful hymns in praise of the Virgin Mary. The history of this period was recorded in a succession of royal chronicles. Pedro López de Ayala (d. 1407), a brilliant writer who searched for motives and realized the importance of social and institutional developments, wrote the excellent chronicles of Peter I, Henry II, John I, and Henry III.
Culture flourished in the Crown of Aragon in the late Middle Ages. After James II founded the University of Lérida in 1300, the first in the realms of Aragon, others were established at Huesca, Barcelona, and Saragossa. Several works of history, generally regarded as gems of Catalan literature, helped to shape the vernacular as a literary language: The Chronicle of James I, purportedly written by the king himself; Bernat Desclot's Chronicle of the Reign of King Peter III; Ramon Muntaner's Chronicle, reporting the adventures of the Catalan Company; and the Chronicle of Peter IV, of which the king claimed to be the author. Ramon Llull (d. 1315), equally facile in Latin, Catalan, and Arabic, was the most prolific writer of the times.