Japanese invasion during World War II ended British rule in Malaya. The subsequent occupation of Malaya, North Borneo and Sarawak from 1942 to 1945 unleashed a wave of nationalism. After the Japanese surrender from Malaya due to being defeated by the Allies, Malayan Union was established in 1946 by the British administration but following opposition by the ethnic Malays, the union was reorganized as the Federation of Malaya in 1948 as a protectorate state until 1957. In the Peninsula, the Malayan Communist Party took up arms against the British and the tension led to the declaration of emergency rule for 12 years from 1948 to 1960. A serious military response to the communist insurgency as well as the Baling Talks in 1955 led to the establishment of independence for Malaya on 31 August 1957 through diplomatic negotiation with the British. Tunku Abdul Rahman became the first Prime Minister of Malaysia. In 1960, the termination of emergency occurred as the communist threat decreased and their withdrawal to the borders between Malaya and Thailand.