He was the youngest son of King Håkon Håkonsson and his wife Margaret Skuladotter. He was born in Tunsberg and was baptised in May 1238. He spent most of his upbringing in Bergen. In 1257 his older brother Håkon died, leaving Magnus the heir-apparent to the kingdom. His father gave him the title of king the same year. On 11 September 1261, he married the Danish princess Ingeborg, the daughter of the late Danish King Erik Plogpenning, after she was practically abducted by King Håkon's men from the monastery she was living in. The struggle to claim Ingeborg's inheritance from her murdered father later involved Norway in intermittent conflicts with Denmark for decades to come. Magnus and Ingeborg were crowned directly after their marriage, and Magnus was given Ryfylke for his personal upkeep. On 16 December 1263 King Håkon died while fighting the Scottish king over the Hebrides, and Magnus became the ruler of Norway.
Foreign policyMagnus' rule brought about a change from the somewhat aggressive foreign policy of his father. In 1266 he gave up the Hebrides and the Isle of Man to Scotland, in return for a large sum of silver and a yearly payment, under the Treaty of Perth, by which the Scots at the same time recognised Norwegian rule over Shetland and the Orkney Islands. In 1269 the Treaty of Winchester cemented good relations with the English king Henry III. Magnus also seems to have had good relations with the Swedish King Valdemar Birgersson, and in the 1260s, the border with Sweden was officially defined for the first time. When Valdemar was deposed by his two brothers and fled to Norway in 1275, this stirred Magnus into gathering a leidang-fleet for the first and only time in his reign. With a large fleet, he met with the new Swedish King Magnus Ladulås to try to bring about a settlement between the two brothers, but without success, Magnus of Sweden would not give in to pressure and the Magnus of Norway retreated without engaging in hostile actions.
Although Magnus was by all accounts a personally very pious king, his work with the law-codes brought him into conflict with the archbishop, who resisted temporal authority over the church, and sought to preserve the church's influence over the kingdom. The Tønsberg Concord (Sættargjerden in Tønsberg) signed in 1277 between King Magnus and Jon Raude, Archbishop of Nidaros, confirmed certain privileges of the clergy, the freedom of episcopal elections and similar matters. The church preserved considerable independence in judicial matters, but gave up its old claim that the Norwegian kingdom was a fief under the ultimate authority of the Catholic Church.
In cultural terms Magnus continued his father's policy of introducing European courtly culture to Norway. In 1277 he replaced the old Norse titles lendmann and skutilsvein with the European titles baron and riddar (knight), at the same time giving them certain extra privileges and the right to be addressed as lord (herra). Magnus is probably also the first Norwegian king to have named himself using an ordinal number - he called himself "Magnus IV" (he did not count Magnus Haraldsson (II) and Magnus Sigurdsson (IV)). Immediately after his father's death, he commissioned the Icelander Sturla Þórðarson to write his father's saga, or biography. In 1278, he commissioned the same man to write his own saga. The Saga of Magnus the lawmender (Magnúss saga lagabœtis) thus became the last of the medieval Norwegian kings' sagas; unfortunately only a short fragment of it has been preserved.
Death and aftermath
In the spring of 1280, Magnus fell ill in Bergen and died 9 May. He had already planned to have his son Eirik crowned at midsummer as co-ruler, instead Eirik now took over as sole king at the age of 12. Real power fell to a circle of advisors, prominent among them Magnus' queen Ingeborg. Magnus was remembered as a good ruler, who ruled by law rather than by the sword. Some modern historians have considered him a weak king, for giving up the Hebrides and giving in to demands of the church, but others consider these wise policies, sparing the kingdom unnecessary and unfruitful wars abroad, while preserving stability at home. Magnus was buried in the church of the Franciscan monastery in Bergen, which has since the 16th century been the Bergen Cathedral (Bergen Domkirke).