Light in the atmosphere doesn’t go in a perfectly straight line. Air slows light down, and denser air slows the light down more. When the air on one side of the beam is being slowed down more than the other side, it makes the light bend in that direction.