The castle of Leiria was built by D.Afonso Henriques for the purpose of creating a line of defense against the Arabs. In 1142 he reinforced the defense of the castle after regaining Leiria. D.Sancho I ordered erection of the walls of the castle in 1195. In 1324 D.Dinis ordered construction of the keep (Tower of Menagem) which was completed only during the reign of D.Afonso IV. In the early 16th century D.Manuel ordered a sacristy to be built between the main chapel and the bell tower.
Throughout the centuries the castle gradually lost its military value. It was badly damaged during the French invasion. At the end of the 19th century restoration of the castle started in 1915 by the initiative of Liga dos Amigos do Castelo. The restoration project was directed by Ernesto Korrodi between 1921 and 1933, and then by Baltazar de Vastro.
The castle hosted important events as the meetings of the first courts called by D.Afonso III; became the residence of D.Denis and Queen Elisabeth; transformed into a meeting venue for the new court in the reign of D. Ferdinand I and the marriage of D. João I's son D. Afonso was celebrated in this castle as well.
It has been listed as a National monument since 1910.
The castle was damaged by the 1969 earthquake.