The hill has been fortified since at least the second century BC, but the walls you walk are largely Islamic-period work of the tenth and eleventh centuries, when the city was ruled from Badajoz as one of the small Muslim kingdoms, called taifas, that divided Iberia at the time. In 1147 Afonso Henriques laid siege to the fortress with an army that included a crusader fleet stopping on its way to the eastern Mediterranean. The defenders surrendered that October, about four months later. The castle then served as a royal palace from 1255 into the early sixteenth century, then declined into barracks and ruin, and what stands today is heavily reconstructed — towers and a curtain wall rebuilt in the twentieth century over what remained.
Inside the walls it is a garden as much as a fortress: olives and pines, peacocks that have the run of the place, and an excavated site where the Alcáçova palace stood. The reason everyone climbs up is the outer terrace. Alfama's roofs fall away below toward the water, the Baixa's grid sits square in the middle distance, and the Tagus runs wide and silver with the bridge across it. It is the one point where the whole shape of Lisbon is legible at once.