About 300 million years ago the earth had dense forests in low lying wetland areas. Due to natural processes, like flooding, these forests got buried under the soil. As more soil deposited over them, they were compressed. The temperature also rose as they sank deeper and deeper. Under high pressure and high temperature, dead plants got slowly converted to coal.
As coal contains mainly carbon, the slow process of conversion of dead vegetation into coal is called carbonisation.