Earthquakes are caused by a sudden release of stress along faults in the Earth's crust. The continuous motion of tectonic plates causes a steady build-up of pressure in the rock strata on both sides of a fault until the stress is sufficiently great that it is released in a sudden, jerky movement. The resulting waves of seismic energy propagate through the ground and over its surface, causing the shaking we perceive as earthquakes.
Earthquakes can also be linked to volcanic activity.
Human activity like tunnel construction, filling reservoirs and implementing geothermal or fracking projects can trigger earthquakes, too (see the question "What are induced earthquakes?").
Detailed explanation of the causes of earthquakes worldwide