In animals with internal fertilization and promiscuous mating, male genitalia show rapid and divergent evolution. Three hypotheses have been suggested to explain the evolutionary processes responsible for genital evolution: the lock-and-key hypothesis, the pleiotropy hypothesis and the sexual-selection hypothesis. Here, we determine whether variation in male genital morphology influences fertilization success in the dung beetle Onthophagus taurus, as predicted by the sexual-selection hypothesis. Variation in four out of five genital sclerites of the endophallus influenced a male's fertilization success, supporting the general hypothesis that male genitalia can evolve under sexual selection. Furthermore, different genital sclerites were found to enhance first versus second male paternity, indicating that different sclerites serve offensive and defensive roles. Genital-trait variability was comparable to that in other species but was less variable than a non-genital sexually selected trait (head horns). We suggest that directional selection for genital elaboration may be countered by natural selection, which should favour genitalia of a size and shape necessary for efficient coupling and sperm transfer.