Twinkling of stars is caused by atmospheric refraction. As starlight passes through different layers of the Earth's atmosphere with varying densities and temperatures, it undergoes repeated refraction in random directions, causing the apparent position and brightness of the star to fluctuate.