Earthquakes are usually caused when the rock underground suddenly breaks along a fault. This sudden outburst of energy causes the seismic waves that make the ground shake. When two blocks of rock or two plates are rubbing against each other, they stick a little.
During the earthquake and afterward, the plates or blocks of rock start moving, and they continue to move until they get stuck again.
Earthquake-like seismic waves can in addition be caused by explosions underground.