There are about 20 plates along the surface of the earth that move continuously and slowly past each other. When the plates squeeze or stretch, huge rocks form at their edges and the rocks shift with great force, causing an earthquake. Think of it this way: Imagine holding a pencil horizontally. If you were to apply a force to both ends of the pencil by pushing down on them, you would see the pencil bend.
After enough force was applied, the pencil would break in the middle, releasing the stress you have put on it. The Earth's crust acts in the same way. As the plates move they put forces on themselves and each other. When the force is large enough, the crust is forced to break. When the break occurs, the stress is released as energy which moves through the Earth in the form of waves, which we feel and call an earthquake.