Recent years have seen a resurgence of interest in the process of speciation but few studies have elucidated the mechanisms either driving or constraining the evolution of reproductive isolation. In theory, the direct effects of reinforcing selection for increased mating discrimination where interbreeding produces hybrid offspring with low fitness and the indirect effects of adaptation to different environments can both promote speciation. Conversely, high levels of homogenizing gene flow can counteract the forces of selection. We demonstrate the opposing effects of reinforcing selection and gene flow in Timema cristinae walking-stick insects. The magnitude of female mating discrimination against males from other populations is greatest when migration rates between populations adapted to alternate host plants are high enough to allow the evolution of reinforcement, but low enough to prevent gene flow from eroding adaptive divergence in mate choice. Moreover, reproductive isolation is strongest under the combined effects of reinforcement and adaptation to alternate host plants. Our findings demonstrate the joint effects of reinforcement, ecological adaptation and gene flow on progress towards speciation in the wild.