The evolution of new species relies on the accumulation of genetic differences that result in reproductive barriers. These barriers frequently act before mating, and many closely related taxa remain separate because they effectively choose not to mate in the first place. Although the significance of behavioural barriers has been recognized at least since the Modern Synthesis, we still know very little about the genetic changes that underlie behavioural divergence in natural populations, or how they are mediated during development. The warning patterns of Heliconius cydno and H. melpomene are under disruptive selection for mimicry, and are also used during mate recognition. I report a genome-wide QTL analysis which reveals that divergent male preference between these species has a surprisingly simple genetic basis. Three QTLs explain 60% of the difference in preference behaviour observed between the parental species. One of these QTLs is physically linked to the major wing patterning gene optix, which causes a switch in forewing colour from white to red. By integrating these results with gene expression and population genomic analyses, we identify a *candidate* gene responsible for shifts in visual mate preference behaviours. Genetic associations between loci for ecological and assortative mating traits are predicted to facilitate speciation in the face of gene flow. Our data also suggest behavioural alleles may be acquired through introgression, allowing reassembly of existing genetic variation into new combinations, further facilitating the rapid evolution of novel behavioural phenotypes and speciation.