The church was built in the second half of the 12th century by the provincial master of the Order of the Knights Templar in Portugal, Gualdim Pais. The current building is mostly the result of a reconstruction carried out in the 13th century in early Gothic style.