Norway was handed to Sweden as compensation for Finland, then left peacefully
After Sweden lost Finland to Russia in 1809, the great powers let it take Norway as a consolation prize. Norway refused, wrote its own constitution and elected its own king before being pushed into a shared crown. Ninety-one years later, in 1905, it walked out without a war.
For centuries Norway had been bound to Denmark, nominally a single kingdom but in practice governed from Copenhagen like a province. Swedish kings had invaded Norway repeatedly, in 1567, 1644, 1658 and 1716, leaving deep resentment. Yet by 1800 Norway's wealthy timber merchants around Christiania, who shipped planks chiefly to Britain, were growing frustrated with Danish rule that denied them a national bank and university, and some quietly looked towards Sweden.
The Napoleonic Wars broke the old order. Denmark-Norway, forced into alliance with France after the British attacked Copenhagen, went to war with Sweden in 1808. A provisional Norwegian government under Prince Christian August held off a Swedish invasion, and his popularity so impressed the Swedes that, after deposing Gustav IV Adolf, they chose their former enemy as crown prince. When he died suddenly in 1810, they turned to another enemy general, the French marshal Bernadotte, who as Crown Prince Charles John made acquiring Norway his central aim and joined the coalition against Napoleon to get it.
The Treaty of Kiel in 1814 obliged Denmark's king to hand Norway over, but Norwegians declared independence, met at Eidsvoll and adopted a constitution on 17 May, electing Prince Christian Frederick king. A short war and the Convention of Moss forced him to abdicate, and on 4 November the Storting chose Sweden's Charles XIII as king of Norway too.
The union was loose. Each country kept its own laws, parliament, church, army and currency; only the monarch and foreign policy, run from Stockholm, were shared. Viceroys governed Norway, first Swedes and later Norwegians, until the post was abolished in 1873. Friction over a separate Norwegian consular service finally led the Storting to declare independence on 7 June 1905. Sweden accepted on 26 October, and after a plebiscite Prince Carl of Denmark took the throne as Haakon VII.
Source: Union between Sweden and Norway