Viborg is situated on the Karelian River Isthmus by the Gulf of Finland. Here, Torgils Knutsson built a castle in 1293. It was the eastern-most castle of the Swedish kingdom and a significant outpost against Russia. The town of Viborg grew up around the castle. Since it was near the Russian border, a town wall was built around it in the 15th century. Except for Viborg, only Stockholm, Kalmar and Visby had town walls in medieval Sweden.
Medieval Viborg traded with goods from Novgorod, mainly hemp, fur, tar and timber. The trade was mainly controlled by merchants of the Hanseatic League.
In 1710 Viborg was conquered by the Russians and at the peace of Nystad, the town became Russian. Viborg was returned to Finland in 1812. Finland was at that time no longer a part of Sweden, but a Russian principality. After Finland became independent in 1917, the town of Viborg grew. In 1939, it was the second-largest town of Finland. During the war of 1939-1940 its population was moved to the west. Since 1945 the town is Russian and the population is now mainly Russian, Ukrainian and Belo-russian.