When light passes from a medium with less refractive index to a medium with higher refractive index, it bends towards the normal. But why normal . Of course we can take an example of a car moving from the road to the mud in an angle. Its first tire decides the direction. But what about light . It's not a car. It's way small and way too fast.
This is due to Fermat's principle, which states that light travels between two points along the path that requires the least time, as compared to other nearby paths. Light travels more slowly in a denser medium, and hence will bend more toward the normal.
Why then does light follow this path, and not other paths? This is because light also obeys the principle of least action, and the action for light is proportional to the time for which it travels. Thus, least action requires that the time taken be minimal.