Animal species display enormous variation for innate behaviours, but little is known about how this diversity arose. Here, using an unbiased genetic approach, we map a courtship song difference between wild isolates of Drosophila simulans and Drosophila mauritiana to a 966 base pair region within the slowpoke (slo) locus, which encodes a calcium-activated potassium channel. Using the reciprocal hemizygosity test, we confirm that slo is the causal locus and resolve the causal mutation to the evolutionarily recent insertion of a retroelement in a slo intron within D. simulans. Targeted deletion of this retroelement reverts the song phenotype and alters slo splicing. Like many ion channel genes, slo is expressed widely in the nervous system and influences a variety of behaviours; slo-null males sing little song with severely disrupted features. By contrast, the natural variant of slo alters a specific component of courtship song, illustrating that regulatory evolution of a highly pleiotropic ion channel gene can cause modular changes in behaviour.