The United States fought in the Korean War in order to stop the spread of communism.
Before American involvement, North Korean communists were badly beating the South Korean democrats. In fear of losing Korea and all of Asia to communism, The United States helped the South Koreans push back the North Koreans. Eventually, communist China ended up helping the North Koreans push back the US, and the war basically ended in a tie.