The area of Montemor-o-Velho, in central Portugal, is inhabited since pre-History, but the first references to the castle date to the 9th century. Being securely under the kingdom of Asturias by 878, it was disputed between Christians and Muslims between the late 10th and the early 12th centuries between Christians and Muslims due to its strategic position along the Mondego and its proximity to Coimbra. The Christians only managed to take the castle definitely in 1034 by Gonçalo Trastamares and was one of the castles which formed the defensive line around Coimbra that defended the city from Almoravid attacks in the early 12th century until the second “taifas” period and Afonso Henriques’ conquests in the Tagus valley in the 1140’s.
Architecturally, the original 9th century castle was repaired in 1085-1091 and probably in 1109 precisely because of its position along the border. In the transition from the 12th to the 13th century the keep tower was built and in the early 14th century, besides reparation works, the castle also received a new ring of walls and a barbican.
The castle (which guarded the medieval settlement) belonged in several periods to princes in Portuguese medieval history like the infantas D. Sancha e D. Teresa (who gave the town its first “foral” in 1212, confirmed in 1248 by Afonso III), princess Branca (daughter of Afonso III), Afonso IV (before he became the King of Portugal) and the infante Peter, Duke of Coimbra. It was one of the favourite places of the court in Afonso IV’s reign precisely due to its strategic place and, according to tradition, this was the site where Inês de Castro’s execution was decided in 6th January 1355.
In 1516 Manuel I gave to Montemor a new “foral” and the town reached a peak of development thanks to the agricultural activities on the Mondego’s valley (namely of corn) and the trade that was made using it. New palaces, churches and nunneries were built or remodeled; the town also was the place of origin of Fernão Mendes Pinto ( explorer, adventurer and the author of Peregrinação) and Diogo de Azambuja (important Portuguese noble and the conqueror of Safi, in Morocco, in 1508). That prosperity lasted until the 17th century, but the river shored up with time and the town (especially the castle, which hadn’t any defensive role anymore and had strict rules for the people who lived inside it) declined, which was made worse by the rise of the town of Figueira da Foz in the 18th century.