Self-medication behaviour is the use of natural materials or chemical substances to manipulate behaviour or alter the body's response to parasites or pathogens. Self-medication can be preventive, performed before an individual becomes infected or diseased, and/or therapeutic, performed after an individual becomes infected or diseased. We summarized all available reports of self-medication in mammals and reconstructed its evolution. We found that reports of self-medication were restricted to eutherian mammals and evolved at least four times independently. Self-medication was most commonly reported in primates. Detailed analyses of primates suggest that self-medication is a life-history trait associated with body size, absolute brain size and longevity, but we found no support for the hypothesis that self-medication evolved to reduce the costs of social living. Large, longer-lived species might thus benefit uniquely from self-medication.