The first references of Castellfollit de la Roca date back to 1110. They are found in a document which mentions the rock of Castellfollit de la Roca, within the viscountcy of Bas. A few years later, in 1193, the chapel of Castellfollit de la Roca castle was also mentioned. In 1344 the village already had its own graveyard and it demanded its own parish. Some families had settled around the castle giving rise to the first village, which was later fortified. At the end of the 14th century, Castellfollit de Roca was a barony which included Sant Joan les Fonts, Begudà, Montagut and Castellar de la Muntanya. Firstly, this barony was related to the Santapau family and was later transferred to different noble families of the town such as the Cruïlles de Santapau, who, in the 16th century, became the counts of Montagut and later Rafaela de Negrell, the Bous and the Croix. In the 17th century, during the Nine Years' War, the French assaulted the castle and, apparently, they demolished it. It was also a strategic place during the Peninsular War. It was in front of the castle where, in 1810, the baron of Eroles together with the rebells defeated the French. Due to all these battles, the fortification was so affected that they were rebuilt in 1875.