In the Middle Ages, the city suffered from repeated pirate attacks and almost disappeared. It resurfaced in the 9th century AD under its current name, under joint protection of the Papacy and the Republic of Pisa.