Denmark–Norway was defeated and had to cede the Kingdom of Norway to the King of Sweden at the Treaty of Kiel. Norway's overseas possessions were kept by Denmark. But the Norwegians objected to the terms of this treaty, and a constitutional assembly declared Norwegian independence on 17 May 1814 and elected the Crown Prince Christian Frederik as king of independent Norway. Following a Swedish invasion, Norway was forced to accept a personal union between Sweden and Norway, but retained its liberal constitution and separate institutions, except for the foreign service. The union was dissolved in 1905.