By the late 9th century, the Vikings had overrun most of the Anglo-Saxon kingdoms that constituted England at the time. However, Alfred the Great, king of Wessex, defeated the Vikings at the Battle of Edington in 878. The resultant treaty gave the Danes control of northern and eastern England, with Alfred and his successors controlling Wessex. But the whole of England was unified with Norway and Denmark in the eleventh century, during the reign of the Danish king Cnut.