The castle of the Knights Templar of Tomar was built by Gualdim Pais, provincial Master of the Order of the Temple, around 1160. Later in that century, the castle was chosen as the headquarters of the order in Portugal. The castle of Tomar was part of the defence system created by the Templars to secure the border of the young Christian Kingdom against the Moors, which at the time (mid-12th century) corresponded approximately to the Tagus river.
The famous round church of the castle of Tomar was also built in the second half of the 12th century. The church, like some other templar churches throughout Europe, was modelled after the Dome of the Rock in Jerusalem, which was believed by the crusaders to be a remnant of the Temple of Solomon. TheChurch of the Holy Sepulchre of Jerusalem may also have served as model.
According to Christian chroniclers, the castle of Tomar resisted in 1190 the attacks of caliph Abu Yusuf al-Mansur, who had previously taken other Portuguese strongholds to the South. A plaque near the entrance of the castle church remembers the feat.