Heritable variation in behavioural traits generally has a complex genetic basis1, and thus naturally occurring polymorphisms that influence behaviour have been defined only in rare instances2,3. The isolation of wild strains ofCaenorhabditis eleganshas facilitated the study of natural genetic variation in this species4and provided insights into its diverse microbial ecology5.C. elegansresponds to bacterial infection with conserved innate immune responses6,7,8and, although lacking the immunological memory of vertebrate adaptive immunity, shows an aversive learning response to pathogenic bacteria9. Here, we report the molecular characterization of naturally occurring coding polymorphisms in aC. elegansgene encoding a conserved HECT domain-containing E3 ubiquitin ligase, HECW-1. We show that two distinct polymorphisms in neighbouring residues of HECW-1 each affectC. elegansbehavioural avoidance of a lawn ofPseudomonas aeruginosa. Neuron-specific rescue and ablation experiments and genetic interaction analysis indicate that HECW-1 functions in a pair of sensory neurons to inhibitP. aeruginosalawn avoidance behaviour through inhibition of the neuropeptide receptor NPR-1 (ref.10), which we have previously shown promotesP. aeruginosalawn avoidance behaviour11. Our data establish a molecular basis for natural variation in aC. elegansbehaviour that may undergo adaptive changes in response to microbial pathogens.