According to some hypotheses, Massafra was founded in the 5th century by refugees from the Roman province of Africa, invaded by the Vandals. The first historical mention of the city dates however from the 10th century, when it was a Lombardgastaldate.
After the Norman conquest of southern Italy, it was given to a nephew of Robert Guiscard, who fortified it and restored the castle. Later it was part of the Principality of Taranto, to which, as a free town, it belonged until 1463. In 1484 it was assigned to Antonio Piscitello. In 1497 it was sacked by the troops of Charles VIII of France, and the fief went to Artusio Pappacoda, whose family held it for a century and a half. They were succeeded by the Carmignano and the Imperiale.