In 1906, there was a large earthquake along the San Andreas Fault in northern California. In the course of field investigations, which among other surprises showed that some spots along the San Andreas had moved by as much as 7 meters, H.F. Reid developed the theory which is most used today to explain earthquakes: the elastic rebound theory.
The elastic rebound theory basically works like this. The rocks along a fault are held together by friction and cannot slip relative to each other. Over time, background geologic forces (which we now know to be mostly plate motions) apply a stress to the rocks on either side of the fault. The blocks of rock ``want'' to slide past one another, but cannot because of the friction holding them together. Instead, they deform around the fault, building up strain energy. Eventually, there comes a point when the strain energy is greater than the strength of the friction holding the rocks together, and they slide past one another abruptly. Voilà -- an earthquake.
Grant Lindley at UCSB has a really cool elastic rebound animation (if you have Java) and some nice pics (if you don't).
Now, there are other kinds of earthquakes which are not directly caused by faults sliding due to plate tectonic stresses. Earthquakes are sometimes caused by volcanoes, by filling reservoirs, by pumping fluids in or out of the ground, and by stresses imposed by big underground nuclear explosions. These sorts of earthquakes are certainly the minority, however.