The palace was initially built by Muhammad I, Umayyad Emir of Cordoba, between 860 and 880. After the Moors were driven out of Toledo in the 11th century, the castle retained its defensive function. Henry III of Castile added several towers. His son John II used it as a royal residence. During the War of the Castilian Succession (1476) the troops of Joanna la Beltraneja were besieged in the Alcázar, during which the building suffered severe damage.