Located at the top of Butte Montmartre, the highest point in the city, it’s much newer than you might think, having only started construction in 1875 and finished in 1914. It was created as penance for losing the Franco-Prussian war of 1870, and the actions of the Paris Commune of 1871.
Though it’s not clear to me which actions exactly needed penance: the Commune’s brutal suppression by the French Army, or the Commune’s progressive and anti-religious policies. As I understand it: officially the former, but the general feeling was that it was really the latter—indeed, a reaction to modern decadent godless civilisation and almost a century of revolutions, and an urge to return to old-school conservative Catholicism.
Sacré-Cœur was extremely controversial during its construction, both for how it displaced residents and its political message.