The events that were occurring in China and in Korea put the United States into a situation that could have led to war. When China became communist in 1949, it was the first time since the end of World War II that a communist group defeated a group that we were actively supporting. We were supporting the Nationalists in the Chinese Civil War. This led to a series of confrontations with China that could have led to war. For example, Communist China wanted to take over Taiwan, which is where the noncommunist government went after losing in 1949, and wanted to make it communist. We threatened Communist China with nuclear attack if they carried out their plans to invade Taiwan.
Regarding Korea, the United Nations led the forces against the North Korean invasion of South Korea. However, the United States took the lead with the forces of the United Nations. General Douglas MacArthur was in charge. After the North Koreans were removed from South Korea, General MacArthur pursued North Korea and nearly conquered the country. He also talked openly about invading China. Since the United Nations responded to help South Korea from becoming communist, going in North Korea and threatening to invade China turned this involvement into something far beyond the goal of containing communism and keeping it from spreading to South Korea.