Castelo Melhor was a Portuguese royal
favourite who, as an effective governor of Portugal from 1662 to 1667 during the reign of
Afonso VI, was responsible for the successful prosecution of the war against Spain, which led to
Spanish recognition of Portugal's new ruling dynasty in 1668. Shortly after Afonso VI's coming-of-age in 1662, Castelo Melhor saw an opportunity to gain power at court when the Afonso's mother,
Queen-Regent Luisa, sent away one of the king's unruly favorites. Melhor managed to convince the angry king to take control of the throne and send his mother to a convent. The King appointed Castelo Melhor his secret notary (escrivão da puridade), a position in which the favourite was able to exercise the functions of first minister. Castelo Melhor overcame the difficulties which had hitherto beset Portugal in the war against Spain, reorganizing the troops (now reinforced by an
English contingent by virtue of the English king
Charles II's marriage to
Catherine of Braganza) and entrusting their command to competent generals. Consequently, the
Portuguese Restoration War entered a victorious phase for Portugal (1663–65) and Spain began peace negotiations. Agreement proved difficult to attain and meanwhile the internal political situation in Portugal deteriorated. Castelo Melhor and his Francophile party were losing ground to the Anglophile party. The king was obliged to dismiss Castelo Melhor on 9 September 1667, in a palace coup organized by the king's wife
Maria Francisca of Nemours and brother
Pedro. Shortly afterwards, the king himself was also deprived of power. Castelo Melhor went into exile in Paris and then London, but in 1685 he was permitted to return to Portugal and, two years after that, to court. On the accession of
John V (1706), he was appointed a councillor of state and he continued to occupy a position of distinction until his death in 1720. He was also the 12th
captain-major of
Santa Maria Island in the
Azores from 1667 to 1720. == References ==