People have lived here for a very long time. Scholars argue about when the caves were first occupied and whether anyone stayed continuously, but the area is believed settled since the Palaeolithic. The town began as caves dug into the softer limestone of the gorge's western face.
The Romans founded a town here in 251 BC under Lucius Caecilius Metellus, and called it Matheola. The Lombards took it in AD 664. In the seventh and eighth centuries Benedictine and Basilian monks moved into the nearby grottos.
The following centuries were rough. Islamic rule began after the Arabs took Bari in 840. Imperial troops burned Matera in 867, and the Arabs held it for a while after a four-month siege in 994. One chronicle calls it a well-defended site. By 1064 it had passed to Robert, Count of Montescaglioso.
Aragon came next, and in 1497 Giancarlo Tramontano bought the city. The people of Matera rebelled in 1514 and killed him, leaving his castle unfinished. In the seventeenth century the Orsini held it. Matera was capital of Basilicata until 1806, when Joseph Bonaparte gave that role to Potenza, and it became capital of its own province in 1927.
The town used to have three parts, Civita and the two Sassi, and they stayed fairly separate until the sixteenth century. Then public life moved out of the walls to Piazza Sedile in the flat Piano to the west, and the wealthy followed from the seventeenth century. By the end of the eighteenth century the peasants in the overcrowded Sassi and the elite in the Piano no longer mixed. The height at which you lived told people your status.
Around 1900 the authorities decided the Sassi were no place for modern life. From 1952 into the 1970s the government moved everyone out to new housing in the Piano, using force in the 1950s. The old town stayed an area of poverty until the late 1980s, and many of its dwellings are still dangerous.
The turn came in 1986, when a new law allowed restoration and people to move back. UNESCO listed the Sassi with the rock churches across the Gravina in December 1993, and visitors followed. Matera was named a European Capital of Culture for 2019, with Plovdiv, in a decision made on 17 October 2014. The architectural historian Anne Toxey points out that the restored houses mostly benefit the wealthy middle class.