After Japan surrendered in 1945, both the Nationalists and Communists sought to control China politically. Because attempts at negotiation and compromise failed, control of China was ultimately decided on the battlefield.
Prior to Japan's surrender, the Communists and Nationalists fought together against Japan in a United Front. Their cooperation, however, disintegrated as soon as Japan lost. The Communists had gained popularity during the war while the Nationalists were relatively ineffective and corrupt.
In December 1945, the United States sent George C. Marshall to China to mediate a peace settlement. But the Communists did not trust the pro-Nationalist U.S. and fighting broke out in many parts of China. After almost a year of trying, Marshall gave up and returned to the U.S.
By 1947, the Communists were winning. They enjoyed support in the countryside, and the Nationalists were on the defensive. The Nationalists' battlefield defeats were exacerbated by inflation and corruption in the areas under their control. The Communists' momentum was inexorable and they took almost all of China by 1949. The Nationalists fled to Taiwan and created a government on that island.
Why did the Communist win? First, they gained more popular support, especially among peasants. Second, they had better leadership. Mao Zedong, the Communist leader, was better than Chiang Kai-shek, head of the Nationalists.