Bressay Sound before sailing for Scotland. After the stalemate of the Battle of Largs, Haakon retreated to Orkney, where he died in December 1263, entertained on his deathbed by recitations of the sagas. His death halted any further Norwegian expansion in Scotland and following this ill-fated expedition, the Hebrides and Mann were yielded to the Kingdom of Scotland as a result of the 1266 Treaty of Perth, although the Scots recognised continuing Norwegian sovereignty over Orkney and Shetland. Absorption by Scotland In the 14th century, Orkney and Shetland remained a Norwegian possession, but Scottish influence was growing. Jon Haraldsson, who was murdered in Thurso in 1231, was the last of an unbroken line of Norse jarls, and thereafter the earls were Scots noblemen of the houses of Angus and St Clair. On the death of Haakon VI in 1380, Norway formed a political union with Denmark, after which the interest of the royal house in the islands declined. In 1469, Shetland was pledged by Christian I, in his capacity as King of Norway, as security against the payment of the dowry of his daughter Margaret, betrothed to James III of Scotland. As the money was never paid, the connection with the Crown of Scotland became permanent. In 1470, William Sinclair, 1st Earl of Caithness, ceded his title to James III, and the following year the Northern Isles were directly absorbed by the Crown of Scotland, an action confirmed by the Parliament of Scotland in 1472. Nonetheless, Shetland's connection with Norway has proved to be enduring. From the early 15th century onward Shetlanders sold their goods through the Hanseatic League of German merchantmen. The Hansa would buy shiploads of salted fish, wool and butter, and import salt, cloth, beer and other goods. The late 16th century and early 17th century were dominated by the influence of the despotic Robert Stewart, Earl of Orkney, who was granted the islands by his half-sister Mary Queen of Scots, and his son Patrick. The latter commenced the building of Scalloway Castle, but after his imprisonment in 1609, the Crown annexed Orkney and Shetland again until 1643, when Charles I granted them to William Douglas, 7th Earl of Morton. These rights were held on and off by the Mortons until 1766, when they were sold by James Douglas, 14th Earl of Morton to Laurence Dundas. 18th and 19th centuries The trade with the North German towns