In 533-4 the Byzantine Empire overthrew the Vandal Kingdom in northwestern Africa and the islands of the western Mediterranean. Trouble in Visigothic Spain in the late 540s gave the opportunity to intervene there and in 552 a Byzantine expedition landed in the south, taking over much of the southern and southeastern coast. The actual extent of their territory is uncertain: at its widest, from the Algarve to the mouth of the River Júcar south of Valencia, but more probably, from the mouth of the Guadalquivir to somewhere beyond Cartagena.
Inland, the city of Córdoba was held by its old Hispano-Roman leadership in defiance of the Visigothic Kingdom and in alliance with the Byzantine Empire. A base had been established for the future conquest of the Visigothic Kingdom, not just for the Empire but for the true and orthodox faith – the Visigothic Kings were Arians. But if that was the purpose it was not pursued: perhaps the real reason for the occupation of part of Spain was the fear that the Visigoths might intervene in northern Africa (the Visigoths were holding Ceuta at the time of the Byzantine conquest of the Vandal Kingdom).
In 568 or 569 Leovigild I became Visigothic King, at first as colleague of his brother, Liuva I. He began the Visigothic recovery. Though he was cautious in acting against the Empire, he destroyed the independence of its ally, Córdoba, in 572. Gradually the Byzantine territories were whittled down, though at the turn of the century they still included Málaga and Cartagena.
In or around 616 a series of Visigothic campaigns began; the last Byzantine possession on the Spanish mainland fell in 624.