The location appears in Norse sagas as Agnafit, and especially in connection with the legendary king Agne. The earliest mention of Stockholm in writing dates from 1252, when the mines in Bergslagen made it an important site in the iron trade. The first part of the name (stock) means log, while the second (holm) means islet, and refers to the islet Stadsholmen in central Stockholm which for centuries constituted the main part of Stockholm.
The city is said to have been founded by Birger Jarl in order to protect Sweden from a sea invasion by foreign navies, and to stop the pillage of towns such as Sigtuna on Lake Mälaren. It is also said that the name derives from the spot where a log (stock) pushed into the waters, and following its currents, drifted upon an islet (holm). This location would thus constitute the best location for a harbor for returning ships.
The strategic and economic importance of the city made Stockholm an important factor in relations between the Danish Kings of the Kalmar Union and the national independence movement in the 15th century. The Danish King Christian II was able to enter the city in 1520. On November 8, 1520, massive executions of opposition figures, called the Stockholm Bloodbath, took place. This massacre set off further uprisings, which eventually led to the break-up of the Kalmar Union.
With the accession of Gustav Vasa in 1523 and the establishment of a royal power, the population of Stockholm began to grow, reaching ten thousand by 1600.
The 17th century saw Sweden rise into a major European power, reflected in the development of the city of Stockholm. From 1610 to 1680, the population multiplied six fold. In 1634, Stockholm became the official capital of the Swedish empire. Trading rules were also created that gave Stockholm an essential monopoly over trade between foreign merchants and other Swedish and Scandinavian territories.
Between 1713–1714, Stockholm suffered from the Black Death. After the end of the Great Northern War and the destruction of several areas of the city in 1721, the city stagnated. Population growth halted and economic growth slowed. However, Stockholm maintained its role as the political centre of Sweden and continued to develop culturally under Gustav III. The royal opera is a good architectural example of this era.
By the second half of the 19th century, Stockholm had regained its leading economic role. New industries emerged, and Stockholm transformed into an important trade and service centre, as well as a key gateway point within Sweden. The population also grew radically during this time, mainly through immigration. At the end of the century, less than 40% of the residents were Stockholm-born. Settlement began to expand outside of the city limits. In the 19th century, a number of scientific institutes opened in Stockholm, including the Karolinska Institute.
In the late 20th century, Stockholm became a modern, technologically-advanced, and ethnically diverse city. Many historical buildings were torn down, including the entire historical district of Klara, and replaced with modern architecture. Throughout the century, many industries shifted away from work-intensive activities into more high-technology and service-industry areas.