The Croats arrived in the 6th century and organised the territory into two duchies by the 9th century. Croatia was first internationally recognised as independent on 7 June 879 during the reign of Duke Branimir. Tomislav became the first king by 925, elevating Croatia to the status of a kingdom. During the succession crisis after the Trpimirović dynasty ended, Croatia entered a personal union with Hungary in 1102. In 1527, faced with Ottoman conquest, the Croatian Parliament elected Ferdinand I of Austria to the Croatian throne. In October 1918, the State of Slovenes, Croats and Serbs, independent from Austria-Hungary, was proclaimed in Zagreb, and in December 1918, merged into the Kingdom of Yugoslavia. Following the Axis invasion of Yugoslavia in April 1941, most of Croatia was incorporated into a Nazi installed puppet state, the Independent State of Croatia. A resistance movement led to the creation of the Socialist Republic of Croatia, which after the war became a founding member and constituent of the Socialist Federal Republic of Yugoslavia. On 25 June 1991, Croatia declared independence, and the War of Independence was fought for four years following the declaration.