Gothenburg is not a medieval town—the current town was founded in the 17th century by King Gustavus Adolphus on the tiny bit of west coast held by Sweden. Right across the river was the frontier with Denmark-ruled Norway, and the border with Denmark-proper was less then 20km away to the south.
Sweden vanquished Denmark by the century’s end and took all of the west coast. Gothenburg was safe, and prospered as the main ocean-faring port of Sweden. Now it’s not just the biggest port in Sweden, but also the second largest city, a student town, and an industrial and innovation hub.