 In the second half of the 9th century, the emir of Córdoba, Muhammad I (852–886), built a fortress on a promontory beside the river, the modern-day location of the Royal Palace.Its purpose was to watch the passes of the Sierra de Guadarrama and to initiate raids against the northern Christian countries.The remaining ruins of the fortress's wall are still preserved.