A crucial assumption in models of ecological speciation is that reproductive barriers evolve as a consequence of ecological divergence of populations, rather than geographical separation. To test the prediction that barriers between populations might evolve in the face of gene flow, we studied reproductive barriers between populations of two Swedish ecotypes of the marine snail Littorina saxatilis with inherited differences in shell size and shape, living in adjacent rocky shore microhabitats with zones of overlap making gene flow between ecotypes possible. We compared mounting frequency and duration between mates of different ecotypes with that between mates of the same ecotype but from populations at various geographical distances. (In this species gene flow is substantially reduced over distances of a few kilometres owing to poor dispersal.) Mates of the same ecotype mated more frequently and for longer than mates of different ecotypes, whereas increased geographical distance did not affect this pattern. Snails of similar sizes more frequently initiated copulation than did snails of different sizes, whereas the duration of copulation was affected by shape. Mating between mates of similar sizes but of different ecotype was more frequently interrupted than mating between the same ecotype. Thus ecological rather than geographical separation in this species has resulted in the evolution of local reproductive barriers. This lends support to models of ecological speciation.