The royal court eventually moved to Madrid and the Alcázar then served as a state prison for almost two centuries before King Charles III founded the Royal Artillery School in 1762.
It was only in 1882 that the building was slowly restored to its original state.