Heritable variation is the raw material for evolutionary change, and understanding its genetic basis is one of the central problems in modern biology. We investigated the genetic basis of a classic phenotypic dimorphism in the nematode Caenorhabditis elegans. Males from many natural isolates deposit a copulatory plug after mating, whereas males from other natural isolates?including the standard wild-type strain (N2 Bristol) that is used in most research laboratories?do not deposit plugs. The copulatory plug is a gelatinous mass that covers the hermaphrodite vulva, and its deposition decreases the mating success of subsequent males. We show that the plugging polymorphism results from the insertion of a retrotransposon into an exon of a novel mucin-like gene, plg-1, whose product is a major structural component of the copulatory plug. The gene is expressed in a subset of secretory cells of the male somatic gonad, and its loss has no evident effects beyond the loss of male mate-guarding. Although C. elegans descends from an obligate-outcrossing, male?female ancestor, it occurs primarily as self-fertilizing hermaphrodites. The reduced selection on male?male competition associated with the origin of hermaphroditism may have permitted the global spread of a loss-of-function mutation with restricted pleiotropy.