Stellar twinkling (scintillation) is caused by atmospheric refraction. As starlight travels through Earth's atmosphere, it passes through layers of air with varying density and temperature. Each layer bends (refracts) the light slightly differently. Because these layers are turbulent and constantly shifting, the light path wobbles—causing the star's apparent brightness and position to fluctuate rapidly.
Twinkling is beautiful to the eye but a headache for astronomers—adaptive optics and space telescopes exist largely to defeat it.