After the withdrawal of Roman military forces, some contacts do appear to have been maintained with the Roman Empire. This led to the establishment of the first Christian monastery in Scotland, at Whithorn, by St Ninian in the early fifth century.
By the early seventh century the region was being taken over by Anglians, pushing westwards from their base in Northumberland. The Anglians rebuilt Whithorn, and built other monasteries at places like Hoddom and Holywood. Whilst the Anglians may have been in the positions of power, it is quite likely that the majority of the people were still British, speaking a language similar to Welsh.
By about 800AD a new presence was being felt in Western Britain, as Vikings plundered monasteries in the Hebrides and Ireland. Within a hundred years they had settled in eastern Ireland, and also overcome the Anglians and settled in northern England. By the early 900s there is evidence of a Viking town being built around the monastery of Whithorn.
Galloway appears to have become a Norse earldom, with links to Ireland, the Hebrides and the Isle of Man. Other Vikings, from northern England, seem to have settled in Annandale and Eskdale. Sandwiched between them was the British territory of Strathnith, stretching north from Dumfries and linked to the British kingdom of Strathclyde.
Some time after 1018 and before 1071, the kingdom of Strathclyde appears to have been conquered by the Scots, and incorporated into the kingdom of Alba, which stretched right down into modern Cumbria. In 1107 David, the younger brother of the Scottish king, Alexander, is made ruler of Strathclyde, 'Prince of the Cumbrians'.