The castle of the Alhambra was added to the city's area within the ramparts in the 9th century, which implied that the castle became a military fortress with a view over the whole city. In spite of this, it was not until the arrival of the first king of the Nasrid dynasty, Mohammed ben Al-Hamar (Mohammed I, 1238-1273), in the 13th century, that the royal residence was established in the Alhambra. This event marked the beginning of the Alhambra's most glorious period.