The division of Korea between North and South Korea happened because of the Allied victory in World War II in 1945. After Japan surrendered, the Allies made Japan give up all the colonies they took through military force, even those before WWII started. Even though Korea was a colony of Japan before WWII, Japan still had to give it up because it used military force to take it over. So after 35 years, Korea no longer became a colony of the Empire of Japan. However, on the same day Japan surrendered, the Soviet Union invaded Korea, after having occupied Northeast China.
The United States and the Soviet Union occupied the country, meaning they had their military there, with the border between their zones of control along the 38th parallel, or the land on the Korean Peninsula from east to west 38 degrees North.
With the rise of the Cold War, negotiations between the United States and the Soviet Union failed to create an independent, unified Korea. In 1948, the elections led by the UN were held only in the southern part of Korea, which was occupied by the United States. This led to the creation of the Republic of Korea in South Korea, which was afterwards followed by the creation of the Democratic People's Republic of Korea in North Korea. The United States supported the South, and the Soviet Union supported the North, and each government claimed sovereignty, or the right to rule itself, over the whole Korean Peninsula.
In 1950, North Korea invaded South Korea in order to take over all of Korea, which began the Korean War. Just before North Korea took over all of Korea, the United States sent its military to take back South Korea. After it took back South Korea, the United States tried to take over North Korea until China, North Korea's communist ally, pushed back the United States. This led to a tug-of-war that lasted throughout the war. In 1953, the fighting ended in stalemate, meaning neither side won the war, and the border was once again put on the 38th parallel, but this time it became the Korean Demilitarized Zone (DMZ).
The Korean War (1950–1953) left the two Koreas separated by the Korean Demilitarized Zone (DMZ) in the later part of the Cold War and even to this day.