Though there are no references to the castle prior to the 1209 charter from Alfonso IX of León, it probably existed in the 9th century in the time of D. Flâmula Rodrigues, on a hypothetical Lusitanian neolithic castle. The medieval enclosure has sections of wall from the 13th century and beyond, although the fortification was not mentioned in 1055, when Fernando de Leão won it from the Moors. There are still two gates with ogival arches called Sun Gate and Traitor’s Gate and another rounded arch in Largo de S. João. The fortification underwent a series of alterations. King Dinis was the mentor of restorations, such as those to the gateway to the caste when he installed a balcony with machicolations and a quadrangular turret with his coat of arms. Later the book by Duarte D´Armas showed the ruins of the fortification and King Manuel I ordered the restoration of the outer walls and awarded a new charter in Santarém on 25 July 1508. The entrances in Rua da Cadeia, such as Alverca Gate, were built later. On the inner NW flank of its walls there is a seat carved out of the rocks, which the local people call the King’s Chair. In the 20th century, it was classified as a National Monument by decree published on 4 July 1922. It was partially restored in the 1940’s but only recently underwent a comprehensive intervention programme organised by the local authority with support from Aldeias Históricas de Portugal.