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.
Stockholm during the Swedish Empire
Erik Dahlberg, c. 1660–1680.
To this end, a reform in 1636 replaced the medieval city council with four committees ("kollegier"), each having a magistrate ("borgmästare") and three aldermen ("rådmän"), responsible for justice, trade, administration, and construction respectively. This reform was most likely triggered by the establishment of the Office of the Over-Governor of Stockholm ("överståthållarämbetet") in 1634, an office designed to be the government's tool in Stockholm and apparently conceived by Axel Oxenstierna himself. The first Over-Governor to be appointed was Claes Fleming (1592–1644, in office 1634–1644). 
Because the management of the city had been a spare time occupation beside regular business activities, appointment to the council had previously been based on experience of commerce. The government, wanting to render municipal management more efficient, was instead devoted to promote men with a theoretical education. Two of them were Anders Torstensson, a man who had a profound impact on the development, and Nicodemus Tessin the Elder, the first City Architect. Furthermore, to increase construction quality the qualifications to admission to the mason's guild, members of which were the de facto architects at this time, were straightened up.