Her father was recalled to England as a potential successor to Edward the Confessor, and he brought the family with him. Edward died right after arrival in the land of his birth, and then the death of Edward the Confessor started a series of events that left the Exile's heir, Edgar Ætheling, unlikely to achieve the throne, though not for lack of trying. When Duke William II of Normandy succeeded at the Battle of Hastings in 1066 and inevitably became King of England, Margaret and her family found a home in Northumbria.
The traditional story is that Margaret's mother, Agatha, decided to take her children back to the continent in 1068. A storm, however, drove them back to land, but farther north, where they were shipwrecked and given refuge by King Malcolm III of Scotland. Malcolm would have been in his late 30s, and Margaret in her early to mid-20s. He took a liking to her, and they were married in 1070. (The illustration is Malcolm greeting Margaret by a Victorian artist.)
Orderic Vitalis wrote that Malcolm had, in fact, traveled to England many years before to speak to Edward the Confessor and ask for his kinswoman's hand in marriage. If this meeting took place, the marriage was delayed for several years. It is possible that the marriage was arranged and then put off against Malcolm's intentions, which might explain Malcolm's plundering of Lindisfarne. Whatever the case may have been, Malcolm was at the time a widower with two sons and would have benefitted from linking himself to the English royal line.
The two had eight children, among which were three kings of Scotland and a queen of England. Tomorrow I'll tell you about their children's fortunes, and then we'll get to her sainthood.