A type of speciation in which there is free exchange of genes between two populations of organisms living in directly adjacent but environmentally different habitats. Although individuals from the two populations can interbreed, this rarely occurs due to morphological, behavioural, or genetic differences, which are reinforced over time, leading eventually to reproductive isolation and formation of distinct species.