Aethelred became king of Wessex in 865 and Alfred became his deputy. In 868 Alfred and Aethelred assisted the King of Mercia whose lands were being attacked by the Danes. Aethelred and Alfred fought the Danes in a series of battles in 870 and 871 defeating the Danes at Ashdown but losing subsequent battles. During one of these battles Aethelred was wounded and died of his injuries. Although Aethelred had sons they were too young to rule and so Alfred succeeded his elder brother as King of Wessex. Alfred's army was no match for the invaders so he came to an agreement and paid them to leave his territories in peace,
Alfred's peace with the Danes lasted until 878 when a Viking army led by Guthrum attacked Alfred's court at Chippenham in the middle of winter. The Saxons were dispersed into marshes around Athelney where they could hide and regroup. Alfred began a period of guerrilla warfare against the Danes from his base in the marshes. The story of Alfred and the burnt cakes probably took place while Alfred was in hiding from the Danes and while he was in disguise. Alfred built up an army including men from Somerset and Wiltshire and arranged for them to meet at Selwood. The large army was then able to overpower the Danes at the battle of Edington. After the battle Guthrum, the leader of the Danes, agreed to be baptised as a Christian by Alfred and agreed to a peace treaty.
After the battle of Edington, although there were smaller raids by the Danes, Wessex moved into a period of relative peace that lasted for the remainder of his reign. Alfred set about creating a series of fortified villages known as burhs. He created a standing army and ensured there were smaller forces of men to provide support at a local level. He also created a small navy.
Alfred dedicated a lot of time to improving his own knowledge and the knowledge of his people. He organised the translation of many works of literature from Latin. He was involved with the Anglo-Saxon Chronicles, ordering copies to be made and their distribution to major abbeys. When Alfred died his son Edward became King of Wessex.