Visby
The two communities parted ways in 1361. When Valdemar IV of Denmark landed on Gotland, the townsmen stayed behind their walls while the island's farmers were cut down outside them, and Visby then opened its gates and had its privileges confirmed. Its trade was already drifting to Lübeck, and pirates soon made the island their base. The Teutonic Order held Gotland from 1398 to 1408, and in 1411 Eric of Pomerania began Visborg Castle at the south end of the town, where in his last years as king and after his fall he lived for more than a decade by raiding Baltic shipping.
In 1525 Lübeck's troops fell on the town at dawn, and the defenders, fleeing to the castle, set fires that burned three churches; with the Reformation nearly all the rest were abandoned. Visby passed to Sweden at the Treaty of Brömsebro in 1645, and when the Danes withdrew after reoccupying it in 1676–79, they blew up Visborg behind them. From the 16th to the 18th century the town stayed so poor that few could afford to pull down its old stone houses, and so medieval Visby survived within its walls.