Theoretically, competition can initiate divergence in habitat use between individuals of a species, leading to restricted gene flow and eventual speciation. Evidence that sister species differ in habitat use is commonplace and consistent with this mechanism, but empirical experimental support is surprisingly scarce. Here we provide evidence that competition has taken a key role in the evolution of genetically distinct ecomorphs of the Lake Tanganyika cichlid fish Telmatochromis temporalis. Experiments show that differences in substrate use between a large-bodied rock-living ecomorph and a neighbouring small-bodied shell-living ecomorph are mediated by size-dependent competition that drives assortative mate-pair formation. Specifically, adults of the larger ecomorph outcompete adults of the smaller ecomorph on favoured rock substrate, compelling the smaller adults to use shell habitat. These results support a role for competition in maintaining reproductive isolation, and highlight the need to identify ecological processes that impose selection to improve our understanding of speciation and adaptive radiation.