This is caused by refraction in the air. This refraction also causes the well-known twinkling of the stars at night.
Astronomers call it 'Seeing'.
But, for an astronomer this is a very bad thing, as he wants to see the celestial objetcts in high detail, which is prevented by those effects. For example, an 8m class telescope could, by mere optical constraints, resolve an object of 25m size on the moon. Therefore, scientists have thought of ways to overcome the seeing effects. The most prominent one is probably the adaptive optics, where the mirror of a telescope is deformed in real-time to compensate for the atmospheric disturbances. Another method that uses postprocessing of the degraded image data is the so-called speckle masking method.