Internal policies
In internal politics, Magnus carried out a great effort to modernise the law-code, which gave him his epithet law-mender. Magnus had several legal scholars and advisors to assist on this work, presumably Audun Hugleiksson, Askatin, Tore Haakonson, and Sturla Tordsson. The modernised law-codes were adopted at the Things in the years 1274 (Landslov) and 1276 (Byloven). In 1274 he promulgated the new national law, known as Magnus Lagabøtes landslov, a unified code of laws to apply for the whole country, including the Faroe Islands and Shetland. This replaced the different regional laws which had existed before. It was supplemented by a new municipal law (a law for the cities) in 1276, Magnus Lagabøtes bylov, and a slightly modified version was also drawn up for Iceland. A unified code of laws for a whole country was at this time something quite new, which had until then only been introduced in Sicily and Castile. His code introduced the concept that crime is an offense against the state rather than against the individual and thus narrowed the possibilities of personal vengeance. It increased the formal power of the king, making the throne the source of justice. The municipal law gave the cities increased freedom from rural control. A specific section fixed the law of succession to the throne, in accordance with the arrangements laid down by King Håkon Håkonsson in 1260.
The royal succession was an important and prickly matter, the last of the civil wars, fought for decades over disputed successions to the throne, having finally ended only in 1240. In 1273 Magnus gave his eldest son, five-year-old Eric, the title of king, and his younger brother Håkon the title of duke, thus making it unequivocally clear who would be his heir.
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 ridder (knight), at the same time giving them certain extra privileges and the right to be addressed as lord (herre). 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.