Masturbation occurs throughout the animal kingdom. At first glance, however, the fitness benefits of this self-directed behaviour are unclear. Regardless, several drivers have been proposed. Non-functional hypotheses posit that masturbation is either a pathology, or a byproduct of high underlying sexual arousal, whereas functional hypotheses argue an adaptive benefit. The Postcopulatory Selection Hypothesis states that masturbation aids the chances of fertilization, while the Pathogen Avoidance Hypothesis states that masturbation helps reduce host infection by flushing pathogens from the genital tract. Here, we present comprehensive new data documenting masturbation across the primate order and use these, in conjunction with phylogenetic comparative methods, to reconstruct the evolutionary pathways and correlates of masturbation. We find that masturbation is an ancient trait within the primate order, becoming a more common aspect of the haplorrhine behavioural repertoire after the split from tarsiers. Our analyses provide support for both the Postcopulatory Selection and Pathogen Avoidance Hypotheses in male primates, suggesting that masturbation may be an adaptive trait, functioning at a macroevolutionary scale.