Sexual imprinting—a phenomenon in which offspring learn parental traits and later use them as a model for their own mate preferences—can generate reproductive barriers between species1. When the target of imprinting is a mating trait that differs among young lineages, imprinted preferences may contribute to behavioural isolation and facilitate speciation1,2. However, in most models of speciation by sexual selection, divergent natural selection is also required; the latter acts to generate and maintain variation in the sexually selected trait or traits, and in the mating preferences that act upon them3. Here we demonstrate that imprinting, in addition to mediating female mate preferences, can shape biases in male–male aggression. These biases can act similarly to natural selection to maintain variation in traits and mate preferences, which facilitates reproductive isolation driven entirely by sexual selection. Using a cross-fostering study, we show that both male and female strawberry poison frogs (Oophaga pumilio) imprint on coloration, which is a mating trait that has diverged recently and rapidly in this species4. Cross-fostered females prefer to court mates of the same colour as their foster mother, and cross-fostered males are more aggressive towards rivals that share the colour of their foster mother. We also use a simple population-genetics model to demonstrate that when both male aggression biases and female mate preferences are formed through parental imprinting, sexual selection alone can (1) stabilize a sympatric polymorphism and (2) strengthen the trait–preference association that leads to behavioural reproductive isolation. Our study provides evidence of imprinting in an amphibian and suggests that this rarely considered combination of rival and sexual imprinting can reduce gene flow between individuals that bear divergent mating traits, which sets the stage for speciation by sexual selection.