Beneath the surface, the earth is made up of layers, and in those layers are geological formations called tectonic plates. Those plates tend to move around and have helped in the formation of oceans and mountains. They are also responsible for such things as earthquakes and volcanoes.
When the plates push against each other or pull apart, they can cause pressure to build up in the gases that exist underground. When those gases get hot, they can cause the crust of the earth to begin to melt, which forms into a substance called magma. When the amount of magma gets to great it will end up getting pushed up through the earth's crust - that results in a volcano and the release of gas and lava.