Cartagena has been inhabited for over two millennia, being founded around 227 BC by the Carthaginian Hasdrubal the Fair as Qart Hadasht (Phoenician, meaning 'New Town') the same name as the original city of Carthage. The city had its heyday during the Roman Empire, when it was known as Carthago Nova (the New Carthage) and Carthago Spartaria, capital of the province of Carthaginensis. It was one of the important cities during the Umayyad invasion of Hispania, under its Arabic name of Qartayannat al-Halfa.
Much of the historical weight of Cartagena in the past goes to its coveted defensive port, one of the most important in the western Mediterranean. Cartagena has been the capital of the Spanish Navy's Maritime Department of the Mediterranean since the arrival of the Spanish Bourbons in the 18th century. As far back as the 16th century it was one of the most important naval ports in Spain, together with Ferrol in the North. It is still an important naval seaport, the main military haven of Spain, and is home to a large naval shipyard.
The town was originally named Mastia. Possessing one of the best harbors in the Western Mediterranean, it was re-founded by the Carthaginian general Hasdrubal in 228 BC as Qart Hadasht ("New City"), identically named to Carthage, for the purpose of serving as a stepping-off point for the conquest of Spain. The Roman general Scipio Africanus conquered it in 209 BC and renamed it as Carthago Nova (literally "New New City") to distinguish it from the mother city. Julius Caesar gave the town Latin Rights, and Octavian renamed it in his honor as the colony Colonia Victrix Iulia Nova Carthago or Colonia Vrbs Iulia Nova Carthago (C. V. I. N. C.) depending on the source. The city was very relevant both in the Carthaginian and the Roman conquest of the Iberian Peninsula. In 298 AD, Diocletian constituted a new Roman province in Hispania called Carthaginensis and settled the capital in this city. It remained important until it was sacked by the Vandals in 435 AD.
The demise and fall Western Roman sovereignty caused the city to go into decline. It was occupied successively by the Vandals (409?425), the Visigoths (425?551 and 624?714) and the Eastern Romans (551?624), who made it the capital of Spania (the Byzantine Empire's westernmost province). Cartagena was re-conquered by the Visigoths, who held it until the Muslim conquest in 714 AD, when it was called Qartayannat-al-Halfa. It was subsequently ruled by the Umayyads (714?756), the Caliphate of Cordova (756?1031), the Taifa of Denia (1031?1076), the Taifa of Saragossa (1076?1081), the Taifa of Tortosa (1081?1092), the Almoravids (1092?1145), the Almohads (1145?1229) and the Taifa of Murcia (1229?1245). King Alfonso X of Castile (Alfonso the Wise) conquered Cartagena in 1245; he reestablished Christian rule and the Bishopric of Cartagena. In 1270, Alfonso created the Order of Santa Mar?a de Espa?a for the naval defense of the Crown of Castile and established its headquarters in Cartagena. In 1296, Cartagena was annexed to the Kingdom of Aragon as the Reconquista focused on the remaining Muslim kingdom, Granada, which fell in 1492. Cartagena entered a period of great decadence and decay, despite a short economic revival in the 16th century, because Spain's colonial activities used ports to the west. Cartagena didn?t fully recover until the 18th century, when it became a leading naval port in the Mediterranean.