|Ferdinand I, son of Pedro the Cruel|
Except that Peter did not have the Castilian throne to pass along. His illegitimate half-brother, Henry of Trastámara, had taken it in 1369 after defeating Peter in the (First) Castilian Civil War. Wanting to oust Peter wasn't a big surprise to much of Europe, since at the time he was more commonly known as "Pedro the Cruel" because of a ruthless administrative style that did not sit well with the aristocracy. Henry had the support of the papacy as well as France and Aragon. France was happy to get involved on the side opposing Peter because of the larger global issues: France was still in the Hundred Years War with England, and England's John of Gaunt (son of King Edward III) was married to Peter's daughter Constance.
Ferdinand was now King of Portugal, but he wanted Castile as well.
Just because Henry sat the throne, however, did not mean his legitimacy was incontrovertible. (He had a son who was not yet a teenager.) Upon Peter's death, King Peter IV of Aragon and King Charles II ("the Bad") of Navarre put forth claims to Castile, as did Peter I's son-in-law, John of Gaunt. (John would have liked a kingdom of his own, since the assumption was that England would go to his older brother, Edward the Black Prince).
Military engagements followed. In order to avoid an unending conflict, all parties appealed to the pope. Pope Gregory IX got everyone to accept a treaty in 1371, agreeing that Peter's son Ferdinand would ascend the throne and would marry Leonora of Castile, Henry's daughter. This would link the thrones of Portugal and Castile by marriage, and everyone would be satisfied.
The next difficulty was created by Ferdinand himself. Although he accepted the treaty, he fell in love with someone else: Leonor Telles de Meneses, the wife of one of his courtiers! He managed to get her forcibly divorced from her husband so that Ferdinand could marry her.
With Henry's daughter spurned, he had no incentive to allow Ferdinand to become king in Henry's place. John of Gaunt plotted with Ferdinand to remove Henry from Castile, and brought an English army to help—to no avail, however, and a treaty in 1373 calmed everyone down again.
Henry died in 1379, and John of Gaunt once again made a claim for the throne. Ferdinand, however, made his own treaty without English help. If Ferdinand's daughter Beatrice were to marry Henry's son John, then the two kingdoms could be joined by marriage to everyone's satisfaction.
When Ferdinand died on 22 October 1383, he left no male heir. Beatrice's marriage to John would have taken care of Castile, but what of Portugal? The treaty was tossed away—popular sentiment was that Portugal would be annexed by Castile; Portugal needed its own king, not that of Castile!—and Ferdinand's illegitimate brother John claimed the throne, sparking a two-year period of war and political uncertainty with the French helping John of Castile and the English helping John of Portugal. When the dust settled, Portugal had gained control of many towns that were originally Castilian, and the two kingdoms were ruled separately.
In 1387, John I of Portugal married Philippa of Lancaster, daughter of John of Gaunt. The alliance between Portugal and England was and remains very strong.