At the end of World War II, the US stayed in South Korea for a while to keep order while the country started to recover from being colonized by Japan. The US also was there because it wanted to keep the Soviets from taking any more of Korea than they already had. While there, the US put a man named Syngman Rhee in power.
But then the US left in 1949. Soon after, in 1950, Dean Acheson gave his speech saying that South Korea was outside the US defense perimeter. This helped cause the Korean War.
When that started, the US became the main protector of South Korea. The US fought off the North Koreans (and later Chinese). After the war, the US left troops in South Korea to protect the country from further attacks.