Afonso appointed Castelo Melhor as his private secretary (escrivão da puridade). He proved to be a competent minister. His astute military organization and sensible general appointments resulted in decisive military victories over the Spanish at Elvas (14 January 1659), Ameixial (8 June 1663) and Montes Claros (17 June 1665), culminating in the final Spanish recognition of sovereignty of Portugal's new ruling dynasty, the House of Braganza, on 13 February 1668 in the Treaty of Lisbon.
Afonso appointed Castelo Melhor as his private secretary (escrivão da puridade). He proved to be a competent minister. His astute military organization and sensible general appointments resulted in decisive military victories over the Spanish at Elvas (14 January 1659), Ameixial (8 June 1663) and Montes Claros (17 June 1665), culminating in the final Spanish recognition of sovereignty of Portugal's new ruling dynasty, the House of Braganza, on 13 February 1668 in the Treaty of Lisbon.