Gene flow from the center of a species' range can stymie adaptation at the periphery and prevent the range from expanding outward. We study this process using simple models that track both demography and the evolution of a quantitative trait in a population that is continuously distributed in space. Stabilizing selection acts on the trait and favors an optimum phenotype that changes linearly across the habitat. One of three outcomes is possible: the species will become extinct, expand to fill all of the available habitat, or be confined to a limited range in which it is sufficiently adapted to allow population growth. When the environment changes rapidly in space, increased migration inhibits local adaptation and so decreases the species' total population size. Gene flow can cause enough maladaptation that the peripheral half of a species' range acts as a demographic sink. The trait's genetic variance has little effect on species persistence or the size of the range when gene flow is sufficiently strong to keep population densities far below the carrying capacity throughout the range, but it can increase the range width and population size of an abundant species. Under some conditions, a small parameter change can dramatically shift the balance between gene flow and local adaptation, allowing a species with a limited range to suddenly expand to fill all the available habitat.