In 1945, Japan surrendered to the USA, and forfeited all territory it had captured in World War II, including the Korean Peninsula. The Soviet Union had also been at War with Japan, and an agreement was reached between the USA, and the USSR that in return for all of Japan's homeland being under US protection, half of the Korean Peninsula would be under Soviet occupation. The northern half of Korea then was influenced by Soviet leadership and adopted Communist economics and politics. The South was influenced by US leadership and adopted democratic politics, and capitalist economics.
When the North invaded the South in 1950, the US had largely withdrawn, and become part of a UN peacekeeping mission, that was supposed to be the first step in re-uniting the peninsula. The US had blocked UN recognition of Communist Red China as the legitimate Chinese government, so the USSR was boycotting the UN Security Council so could not veto a resolution deeming the invasion to be an Act of War. That put North Korea at war with the UN. The US launched the Inchon landings and drove the invasion back.
When US led forces encroached on the Yalu River, Red China counter-invaded and reestablished the North. The war degenerated into a stalemate along a front where the DMZ exists today.
In 1953 both sides signed an ARMISTICE (not a peace treaty) that ended the fighting, but didn't end the war. That was the status until the last few weeks of spring 2013, now the North has declared the armistice over, and is on the verge of reigniting the war.