King Magnus VII ruled Norway until 1350, when his son, Haakon, was placed on the throne as Haakon VI. In 1363, Haakon VI married Margaret, the daughter of King Valdemar IV of Denmark. Upon the death of Haakon VI, in 1379, his son, Olaf IV, was only 10 years old. Olaf had already been elected to the throne of Denmark on 3 May 1376. Thus, upon Olaf's accession to the throne of Norway, Denmark and Norway entered personal union. Olaf's mother and Haakon's widow, Queen Margaret, managed the foreign affairs of Denmark and Norway during the minority of Olaf IV.