Light travels faster in thin air than thick air. Thus, when sunlight passes through the different layers of the atmosphere, it is bent toward the thinner air and this bending is at such an angle as to reach our eyes after the actual sun is below the horizon. The total effect of this refraction is to increase the actual time of daylight as compared to having no atmosphere at all. A mirage is a displaced image cause by refraction. A ray of light from a star passes through shifting air currents and thus appears to be coming in from different directions.
Refraction is the bending of light cause by a speed change when it passes through different media.
When a cart wheel rolls from a smooth sidewalk onto a plot of grass, the interaction of the wheel with the blades of grass slows the wheel. The absorption-reemission from molecule to molecule differs for different frequencies in different media. This is the effect that changes the speed of light in those different media. When light passes from one material into another, it may bend toward the normal to the surface. Or it may bend away from the normal.