 Shortly after Afonso VI's coming-of-age in 1662, Castelo Melhor saw an opportunity to gain power at court by befriending the mentally unstable king.He managed to convince the king that his mother, Luisa of Medina-Sidonia, was out to steal his throne and exile him from Portugal.As a result, Afonso took control of the throne and his mother was sent to a convent.