The short answer is that earthquakes are caused by faulting, a sudden lateral or vertical movement of rock along a rupture (break) surface.
Here's the longer answer: The surface of the Earth is in continuous slow motion. This is plate tectonics--the motion of immense rigid plates at the surface of the Earth in response to flow of rock within the Earth. The plates cover the entire surface of the globe.
Since they are all moving they rub against each other in some places (like the San Andreas Fault in California), sink beneath each other in others (like the Peru-Chile Trench along the western border of South America), or spread apart from each other (like the Mid-Atlantic Ridge). At such places the motion isn't smooth--the plates are stuck together at the edges but the rest of each plate is continuing to move, so the rocks along the edges are distorted (what we call "strain").
As the motion continues, the strain builds up to the point where the rock cannot withstand any more bending. With a lurch, the rock breaks and the two sides move. An earthquake is the shaking that radiates out from the breaking rock.
People have known about earthquakes for thousands of years, of course, but they didn't know what caused them. In particular, people believed that the breaks in the Earth's surface--faults--which appear after earthquakes, were caused *by* the earthquakes rather than the cause *of* them. It was Bunjiro Koto, a geologist in Japan studying a 60-mile long fault whose two sides shifted about 15 feet in the great Japanese earthquake of 1871, who first suggested that earthquakes were caused by faults. Henry Reid, studying the great San Francisco earthquake of 1906, took the idea further.
He said that an earthquake is the huge amount of energy released when accumulated strain causes a fault to rupture. He explained that rock twisted further and further out of shape by continuing forces over the centuries eventually yields in a wrenching snap as the two sides of the fault slip to a new position to relieve the strain. This is the idea of "elastic rebound" which is now central to all studies of fault rupture.
Source: Dr. Gerard Fryer / University of Hawaii.