Finland was still part of Sweden during the 18th century. Sweden had become a major power during the 17th century, but it lost its position on the first half of the 18th century as both the Great Northern War (1700–1721) and the 20 years later fought Russo-Swedish War (1741–1743) ended in Swedish defeat. Along with the treaties of Uusikaupunki and Turku, which were signed at the end of the wars, Sweden lost southeastern Finland to Russia. Defence of the eastern border became even more difficult than before as the fortress cities of Hamina, Lappeenranta and Savonlinna were left on the Russian side. A new fortress city was needed.
There were a few alternatives for placement of the new fortress. One was Porvoo, but it was located slightly too far from the border. Another alternative was Markkinamäki at the western bank of the Kymijoki river, but this was in turn a little too close to the border. The own troops would not have had sufficient time to prepare for defence had the Russians attacked. In addition, there was an iron works in the vicinity of Markkinamäki. The owner of the iron works did not want a city that close for fear of this impeding the supply of wood for the needs of the iron works. The best possible alternative appeared to be the Degerby farm obliged to furnish a cavalryman, located in Pernaja parish. The location was deep in the protection of a bay, where it was easy to build a harbour. The town was granted staple rights, i.e. rights to conduct international trade.
Seven years later, in 1752, The Swedish king Adolf Frederick visited the town during his inspection journey. As a result of the visit the name of the town was changed from Degerby to Loviisa according to queen Louisa Ulrika. Augustin Ehrensvärd drafted during the 1740ies a comprehensive fortress plan for the eastern Gulf of Finland. According to this plan land and sea fortresses were to be built in Helsinki and in Loviisa. Only the sea fortress of Sveaborg (nowadays known as Suomenlinna) was built in Helsinki. Here in Loviisa in addition to the Svartholma sea fortress were built on the mainland the bastions Ungern and Rosen, two barracks and the commandant’s house, which today houses the Loviisa town museum.