It is the movement of tectonic plates that causes earthquakes. It depends which plates as there are a few different types, but basically a plate will get caught/jammed/stuck with another plate. Whilst they are stuck, pressure builds up and eventually it is released. As the plated jolt back into position, the pressure that has been building up is released as huge amount of energy - this is an earthquake.