Tradition says King Olav Kyrre founded Bergen in 1070, but a trading settlement was already there in the 1020s or 1030s. It was called Bjørgvin, a name meaning a green meadow among the mountains. It began as a small port and trading post at what is now Bryggen.
In the 13th century Bergen was in effect Norway's capital. The 1150s saw the first royal coronation in the country here, and the fortress dates from the 1240s. The title passed to Oslo under Haakon V, who ruled from 1299. Håkonshallen and the Rosenkrantz tower are what you can still visit of that royal town.
Dried cod from northern Norway made the town rich. Merchants from north Germany ran a Hanseatic League trading post at Bryggen, one of only four such Kontore, lived in their own quarter and used Middle Low German. Fishermen sailed south each summer, and the city held a monopoly on trade with the north until 1789. The Hanseatic office closed in the 1750s, but Norwegian merchants had been taking over since about 1600.
Wood and fire shaped the rest of the story. The record lists blaze after blaze, from a drunk trader's fire at Bryggen in 1476 to the great fire of 1702, which burned 90% of the town. The wooden houses at Bryggen today date from after 1702. More fires hit the Strandsiden shore in the 18th century, and 1916 took hundreds of buildings in the city centre. Only a few masonry buildings survive from the Middle Ages, among them Mariakirken and Håkonshallen.
Not everything that paid for the old town is pleasant to read about. The Black Death reached Norway in 1349 on an English ship that docked in Bergen. In the 17th century the shipowner Jørgen Thormøhlen, the largest in Norway, held the main share in the Cornelia, a slave ship that sailed twice, in 1673 and 1674. He also built up industry in the district now named after him, Møhlenpris.
Oslo overtook Bergen as Norway's largest city in the 1830s. The isolation lasted for decades more: until the railway opened in 1909, the practical way east was several days by sea around the coast. Meanwhile the bare grey hills above town were planted with trees from the late 1800s, which is why Fløyen's slopes are now forest. Research grew too. Armauer Hansen showed in 1873 that leprosy is caused by a bacterium, and the Bergen school of meteorology laid the basis for modern weather forecasting.
German forces took Bergen on 9 April 1940, the first day of the invasion. On 20 April 1944 a Dutch cargo ship carrying more than 120 tons of explosives blew up off the fortress, killing at least 150 people and damaging old buildings. The roof of Håkonshallen was rebuilt after the blast. Today about 294,860 people live in the municipality, which swallowed Arna, Fana, Laksevåg and Åsane in 1972, and its port is Norway's busiest.