Animals that maintain cooperative relationships show gains in longevity and offspring survival. However, little is known about the cognitive or hormonal mechanisms involved in cooperation. Indeed, there is little support for a main hypothesis that non-human animals have the cognitive capacities required for bookkeeping of cooperative exchanges. We tested an alternative hypothesis that cooperative relationships are facilitated by an endocrinological mechanism involving oxytocin, a hormone required for bonding in parental and sexual relationships across mammals. We measured urinary oxytocin after single bouts of grooming in wild chimpanzees. Oxytocin levels were higher after grooming with bond partners compared with non-bond partners or after no grooming, regardless of genetic relatedness or sexual interest. We ruled out other possible confounds, such as grooming duration, grooming direction or sampling regime issues, indicating that changes in oxytocin levels were mediated by social bond strength. Oxytocin, which is thought to act directly on neural reward and social memory systems, is likely to play a key role in keeping track of social interactions with multiple individuals over time. The evolutionary linkage of an ancestral hormonal system with complex social cognition may be the primary mechanism through which long-term cooperative relationships develop between both kin and non-kin in mammals.