According to tradition, the town was founded around 1000 AD by two pilgrims, Arcanus and Aegidius, who brought a stone from the Church of the Holy Sepulchre (thus, San Sepolcro) with them from the Holy Land. They founded an oratory dedicated to Saint Leonardo, on the site of the current Cathedral.
The first historical mentions of Sansepolcro are slightly later, referring to the Benedictine Abbey, the "Badia", around which the walled commune clustered. During the conflicts between Guelfs and Ghibellines, the town's factions were headed by prominent local families, including the Pichi, Bercordati, Graziani and Bacci.
The city was ruled from Citta' di Castello, Milan, then by the Papacy; in 1367 Pope Urban V gave the town and its surrounding contada to Galeotto Malatesta family, whose heirs ruled it until control was assumed by Florence.
During World War II the town was saved from destruction by the efforts of Tony Clarke, a British Royal Horse Artillery officer who halted the Allied artillery attack in order to save Piero della Francesca's fresco Resurrection