With the end of World War II, the United States adopted a confrontational stance against the Soviet Union. Concerned about the continued spread of communist influence across the world, the Truman administration unveiled a policy of containment, aimed at preventing the further spread of communism as much as possible. This history would shape the beginning of the Cold War, a geopolitical power struggle between the United States and the Soviet Union that would dominate much of the remainder of the twentieth century.
This political context is critical to understanding American intervention in the Korean War, given American concerns about further spread of communist influence in Asia. With the end of World War II, control of China fell rapidly to the Communists, who completed the takeover of the country in 1949, with the Nationalist government retreating to Taiwan.
Meanwhile, Japan's surrender to the United States brought the country under US occupation, even as Korea was split into two zones of occupation, with the southern part of the country surrendering to the United States and the northern part surrendering to the USSR. This division proved permanent, as both the Soviets and Americans supported the creation of separate governments, with North Korea coming under the control of Kim Il Sung and South Korea under the control of Syngman Rhee.
The Korean crisis triggered in 1950, when North Korea invaded South Korea, aiming to reunify the country. From the perspective of the United States, concerned about the further spread of communism in Asia and in the world, such an outcome could not be allowed, and so the United States responded by intervening, bringing UN assistance in the process.