Korea had been divided in 1945 at Potsdam into North and South across the 38th parallel. Both USA and USSR wanted to ensure their zone were secure from military threats and had strong leaders.
USA asked the UN to call a ceasefire. UN voted for withdrawal of North Korean troops from the south. The USSR was boycotting the UN so they could not veto the decision.
The USA sent troops to support Rhee and as they had UN support they couldn't be accused of acting on its own.
Showed USA commitment to contain Communism. Showed power USA had in UN. Dismissal of MacArthur showed they did not want to risk full military engagement with the USSR, who thought the same thing.