When light travels from one medium to another it changes its direction because of refraction. The direction only changes if the speed of light changes too. Thus when light travels from a dense to a rare medium, it's path will deviate from the normal path.