The Palácio Nacional de Mafra was begun in 1717 by King João V of Portugal in fulfillment of a vow made to obtain an heir from his Habsburg queen, Maria Anna of Austria. Their daughter Maria Bárbara, the future Queen of Spain, had been born in 1711, and the king kept his promise on an extraordinary scale. The architect was Johann Friedrich Ludwig (João Frederico Ludovice), a German-trained jeweller and architect who had worked in Rome under Carlo Fontana and brought a late Roman baroque idiom to the Estremadura limestone hills.
Construction lasted into the 1750s, with 52,000 workers reportedly on site at peak and 1,383 documented worker deaths. The complex was funded almost entirely by the Brazilian gold cycle — the alluvial diamonds and gold of Minas Gerais that briefly made Portugal the richest crown in Europe. The basilica was consecrated in 1730 in time for the king's birthday. The 220-metre main façade encloses a 38,000 m² floor plan with 1,200 rooms, 4,700 doors and windows, two bell towers carrying a 92-bell carillon, and a single basilica dome.
Three features are unique. The first is the basilica's six historic pipe organs — built between 1792 and 1807 by António Xavier Machado e Cerveira and Joaquim António Peres Fontanes to a specification that allows all six to be played together as a single 30,000-pipe instrument. The second is the baroque library, 88 metres long, holding 36,000 leather-bound volumes from the 14th to the 19th century, where a resident colony of small bats (Pipistrellus and Plecotus species) is left undisturbed because they eat the insects that would otherwise eat the books. The third is the Tapada de Mafra — a 1,200-hectare walled hunting park behind the palace, the largest enclosed royal hunting reserve in Europe, still home to red deer, wild boar and Iberian fallow deer.
The 'Royal Building of Mafra — Palace, Basilica, Convent, Cerco Garden and Hunting Park' was inscribed on the UNESCO World Heritage list in 2019. The complex appears in José Saramago's 1982 novel Baltasar and Blimunda, which dramatizes the lives of the workers who built it and won Saramago the literary recognition that led to his 1998 Nobel Prize.