Prehistory and origin of Stockholm
According to the Chronicle of Eric, written in the 1320s, Stockholm was founded by Birger Jarl around 1250 as a lock to the Lake Mälaren region ("laas fore then sio", "lock before that lake") in order to prevent pirates from reaching the seven cities and nineteen parishes around it. Another medieval source ("Visbyannalerna"), however, claims the city was founded in 1187 following a pagan pillaged the city of Sigtuna, and as there was an "Earl" named Birger around at that time too, the disputed origin of the city are likely to remain obscure and some historians choose a diplomatic interpretation saying there was some sort of fortification around by the mouth of lake Mälaren when the city was founded during the second half of the 13th century. As Snorri mentions no city in his account but some sort of fortification called a "kastali" (in various manuscripts curiously said to be located east and west of "Stocksund"), it has generally been assumed this fortification eventually developed into the castle Tre Kronor located where still is the Stockholm Palace.
History of Sweden (800–1521)
The greatest medieval statesman of Sweden, and one of the principal architects of its rise as a nation – Birger Jarl the Regent – practically ruled the land from 1248 to 1266. He is today revered as the founder of Stockholm and as the creator of national legislations. His reforms paved the way for the abolition of serfdom. The increased respect and power which later royals owed to Birger Jarl were further extended by his son, King Magnus Ladulås (1275–90). Both these rulers, by the institution of separate and almost independent duchies, attempted to introduce into Sweden a feudal system similar to that already established in continental Europe; the danger of thus weakening the realm by partition was averted, though not without violent and tragic complications by the opponents, the Folkung party. (The term "Folkung" also later referred to Earl Birger's descendants, forming the royal Folkunge of Bjelbo dynasty.) Finally, in 1319, the severed portions of Sweden were once more reunited.