How did the US stop the spread of communism after world war 2?

We engaged communist forces in the Korean and Vietnam wars which also led to the downfall of the soviet union