The atmosphere is made up of layers of different optical densities. This is because density of gases in atmosphere changes with temperature which result in change of refractive index.
The deviation of light or other electromagnetic waves from a straight line as it passes through the atmosphere is known as atmospheric refraction.
The star twinkles due to atmospheric refraction of starlight.
The star twinkles as a result of the atmospheric refraction of starlight.