The history of Norway has been influenced to an extraordinary degree by the terrain and the climate of the region. About 10,000 BC, following the retreat inland of the great ice sheets, the earliest inhabitants migrated north into the territory which is now Norway. They traveled steadily northwards along the coastal areas, warmed by the Gulf Stream. They were hunter-gatherers whose diet included seafood and game, particularly reindeer as staple foods. Between 5,000 BC and 4,000 BC the earliest agricultural settlements appeared around the Oslofjord. Gradually, between 1500 BC and 500 BC, agricultural settlements spread to the entire south Norway, while the inhabitants of the regions north of Trøndelag continued to hunt and fish.
The Neolithic period started in 4000 BC. The Migration Period caused the first chieftains to take control and hilltop forts to be constructed. From the 8th century Norwegians started expanding across the seas to the British Isles and later Iceland and Greenland. The Viking Age also saw the unification of the country. Christianization was completed during the 11th century and Nidaros became an archdiocese. The population expanded quickly until 1349 (Oslo: 3,000; Bergen: 7,000; Trondheim: 4,000) when it was halved by the Black Death and successive plagues. Bergen became the main trading port, controlled by the Hanseatic League. Norway entered the Kalmar Union with Denmark and Sweden in 1397.
After Sweden left the union in 1523, Norway became the junior partner in Denmark–Norway. The Reformation was introduced in 1537 and absolute monarchy imposed in 1661. In 1814, after being on the losing side of the Napoleonic Wars with Denmark, Norway was ceded to the king of Sweden by the Treaty of Kiel. Norway declared its independence and adopted a constitution. However, no foreign powers recognized the Norwegian independence but supported the Swedish demand for Norway to comply with the treaty of Kiel.