The Korean War was in many ways a logical conclusion of the US policy of containment in the wake of World War II. While this strategy, formally expressed as the Truman Doctrine, had previously applied to Western Europe, the rise of communism in China had made east Asia a strategic priority for the United States, especially as it threatened, they thought, Japan, which was still rebuilding.
So when communist North Korean forces, with at least the implicit approval of the Soviet Union and China, invaded South Korea, Truman felt that intervention was necessary. He thus sent hundreds of thousands of US troops to join the so-called UN "police action." While no war is inevitable, internal politics (Truman feared being painted as "soft on communism") and US geopolitical doctrine made it very difficult to resist intervention on the Korean peninsula.