Adaptive ecological differentiation among sympatric populations is promoted by environmental heterogeneity, strong local selection and restricted gene flow. High gene flow, on the other hand, is expected to homogenize genetic variation among populations and therefore prevent local adaptation. Understanding how local adaptation can persist at the spatial scale at which gene flow occurs has remained an elusive goal, especially for wild vertebrate populations. Here, we explore the roles of natural selection and nonrandom gene flow (isolation by breeding time and habitat choice) in restricting effective migration among local populations and promoting generalized genetic barriers to neutral gene flow. We examined these processes in a network of 17 breeding ponds of the moor frog Rana arvalis, by combining environmental field data, a common garden experiment and data on variation in neutral microsatellite loci and in a thyroid hormone receptor (TRβ) gene putatively under selection. We illustrate the connection between genotype, phenotype and habitat variation and demonstrate that the strong differences in larval life history traits observed in the common garden experiment can result from adaptation to local pond characteristics. Remarkably, we found that haplotype variation in the TRβ gene contributes to variation in larval development time and growth rate, indicating that polymorphism in the TRβ gene is linked with the phenotypic variation among the environments. Genetic distance in neutral markers was correlated with differences in breeding time and environmental differences among the ponds, but not with geographical distance. These results demonstrate that while our study area did not exceed the scale of gene flow, ecological barriers constrained gene flow among contrasting habitats. Our results highlight the roles of strong selection and nonrandom gene flow created by phenological variation and, possibly, habitat preferences, which together maintain genetic and phenotypic divergence at a fine-grained spatial scale.