João's queen, Luísa de Gusmão, becomes regent on her husband's death because the royal couple's oldest son, Teodosio, had died three years before his father and their youngest son, Afonso, is only ten years old.
Although a disease in infancy had left Afonso partially paralyzed and had impaired his intelligence, his mother succeeds in having him proclaimed king.
Afonso VI (r. 1662-67) grows into a degenerate who prefers riding, coursing bulls, and watching cockfights.
His marriage to Marie-Francoise Isabelle of Savoy is annulled, and, in 1667, aware of the need for a successor, Afonso consents to his own abdication in favor of his brother, Pedro.
During this period, the Portuguese manage to fight off the last attempt by Spain to reincorporate them into the Iberian Union by defeating the Spanish invaders at Ameixial near Estremos.
In 1666, three years after this victory, Spain at last makes peace and recognizes Portugal's independence.