The Union of Sweden and Norway came about as a result of the Napoleonic Wars, when the king of Denmark–Norway, on the losing side, was forced to cede Norway to the king of Sweden by the Treaty of Kiel in 1814. Norwegian resistance led to the declaration of national independence and the adoption of a constitution on 17 May 1814. A brief war with Sweden resulted in the Convention of Moss on 14 August 1814 and the Norwegian constitutional revision of 4 November 1814 to open the way for a personal union. On the same day, the Norwegian parliament chose to elect Charles XIII of Sweden as King of Norway.