From quorum sensing in bacteria to pheromone signalling in social insects, chemical communication mediates interactions among individuals in local populations. In Caenorhabditis elegans, ascaroside pheromones can dictate local population density; high levels of pheromones inhibit the reproductive maturation of individuals. Little is known about how natural genetic diversity affects the pheromone responses of individuals from diverse habitats. Here, we show that a niche-associated variation in pheromone receptor genes contributes to natural differences in pheromone responses. We identified putative loss-of-function deletions that impair duplicated pheromone receptor genes (
srg-36 and
srg-37), which were previously shown to be lost in population-dense laboratory cultures. A common natural deletion in
srg-37 arose recently from a single ancestral population that spread throughout the world; this deletion underlies reduced pheromone sensitivity across the global C. elegans population. We found that many local populations harbour individuals with a wild-type or a deletion allele of
srg-37, suggesting that balancing selection has maintained the recent variation in this pheromone receptor gene. The two
srg-37 genotypes are associated with niche diversity underlying boom-and-bust population dynamics. We hypothesize that human activities likely contributed to the gene flow and balancing selection of
srg-37 variation through facilitating the migration of species and providing a favourable niche for the recently arisen
srg-37 deletion.