Ventimiglia is the ancient Albium Intemelium, the capital of the Intemelii, a Ligurian tribe which long resisted the Romans, until in 115 BC it was forced to submit to Marcus Aemilius Scaurus. In AD 69 the city was sacked by the army of Otho and Vitellius, but recovered to remain prosperous into the 5th century, surrounded by walls with cylindrical towers built at each change of direction.
In the Gothic Wars it was besieged by the Byzantines and the Goths, and later suffered from the raids of Rothari, King of the Lombards, but flourished again under Rodoald. After the fall of Charlemagne's empire, Berengar II of Italy made his son Conrad first Count of Ventimiglia. In the 10th century it was attacked by the Saracens of Fraxinet. After a period as an independent commune, it was ruled by the Counts of Ventimiglia, and often had to fight with the Republic of Genoa.
In 1139 the Genoese attacked it by land and sea and forced it to surrender; the count continued to hold the city and countship as a vassal of the victors. The city rebelled more than once against the Genoese and sided with their enemies. In 1271 in a war with Genoa its podestà Luca Grimaldi was captured. Ventimiglia was thus temporarily held by the dukes of Savoy (1389 and 1746) and King Ladislaus of Naples (1410). In 1505 it was annexed to the Genoese Republic, sharing its history until the early 19th century