How do you define 'legitimate'? Historically (in England at least), might made right. If you could kill your competetors yours was the throne (e.g. Henry IV, Henry VII).
Enrique II of Castilla, ilegitimate son of Alfonso XI with Leonor de Guzmán.
Pedro I "the cruel" was Alfonso XI´s only legitimate surviving son and inherited the kingdom of Castilla after his father death (of black plague) in 1350.
Enrique killed Pedro in 1369 and took the throne becoming the first king of the house of Trastámara.
Pedro I had named his son Juan heir to the throne, but this son was declared illegitimate and in any case Enrique imprisoned him.
Here's a similar question by me, might help you. Not many answers, though.