Mercia was the dominant kingdom in southern England in the eighth century, and maintained its position until it suffered a decisive defeat by King Egbert of Wessex at the Battle of Ellandun in 825. Egbert briefly conquered Mercia, but it recovered its independence in 830, and thereafter the two kingdoms became allies, which was to be an important factor in English resistance to the Vikings. The Mercians traditionally held overlordship over Wales, and in 853 King Burgred of Mercia obtained the assistance of King Æthelwulf of Wessex in an invasion of Wales in order to reassert their hegemony. The same year, Burgred married Æthelwulf's daughter.
In 865 the Viking Great Heathen Army landed in East Anglia, and used it as a starting point for an invasion. The East Anglians were forced to buy peace, and the following year the Vikings invaded Northumbria, where they established an obscure Northumbrian man called Egbert as puppet king in 867. They then moved on to Nottingham in Mercia, where they spent the winter of 867–868. Burgred was joined by King Æthelred of Wessex and his brother, the future King Alfred, for a combined attack on the Vikings, but they refused an engagement and in the end the Mercians bought peace with them. The following year, the Vikings conquered East Anglia. They returned to Mercia in 872; two years later they expelled Burgred, and Ceolwulf became king with their support. Ceolwulf was described by the Anglo-Saxon Chronicle as "a foolish king's thegn" who was a puppet of the Vikings, but the historian Ann Williams regards this view as partial and distorted: he was accepted as a true king by the Mercians and by King Alfred.
In 877 the Vikings divided Mercia, taking the eastern part for themselves and leaving Ceolwulf with the west. The Vikings went on to attack Wessex, leaving Ceolwulf free to renew Mercian claims of hegemony in Wales. At almost the same time as Alfred's victory over the Vikings in 878 at the Battle of Edington, Ceolwulf defeated and killed Rhodri Mawr, king of the north Welsh territory of Gwynedd. After Ceolwulf's disappearance in 879, Mercia began to fall under the hegemony of Wessex.