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.
Prehistory and origin of Stockholm
Of the half dozen trade posts in Sweden described in 1120 as cathedral cities, or cities with a potential to become such, Sigtuna is believed to be the only one with the density and status of a city in the proper sense. This quickly changed as German merchants introduced developed forms of production and 'industrialised' Swedish mining, mostly during the second half of the 13th century. This rewrote the regional map and resulted in the gradual development of a Swedish urbanity. As trade routes moved westward in the Mälaren region, Sigtuna found itself left astern.
Birger jarl's elimination of the "true Folkungs" between 1247 (Battle of Sparrsätra) and 1251 (Battle of Herrevadsbro) lead to increased consolidation of the Swedish kingdom and the introduction of a continental feudal society. Additionally, the Swedish dominion expanded east as Birger jarl and Torgils Knutsson conquered Tavastland and Karelia (later Finland) which placed present-day Stockholm, until then an insignificant peripheral island, in the absolute centre of the small empire.