Natural selection proceeds in small, local steps; each change has to be advantageous in the short term. It is possible for natural selection to climb to a local optimum, where the population may be trapped because no local change is advantageous, although a large change could be. Selection itself - when considered in a fully multidimensional context - or neutral drift may lead the population away from local peaks, but also it may not. Some natural populations may now be imperfectly adapted because the accidents of history pointed their ancestors in what would later become the wrong direction.
Figure: accidents of history. Historical change in adaptive topography leaves a species stranded on a local peak. (a) Initially, there is a single optimum state for a character, and the population (X ) evolves to that peak. (b) As the environment changes through time, the adaptive topography has changed, and a new global peak has arisen. The species is stuck at the local peak, because evolution to the global peak would traverse a valley: selection does not favor evolution toward the global peak.