People who are more socially integrated or have higher socio-economic status live longer. Recent studies in non-human primates show striking convergences with this human pattern: female primates with more social partners, stronger social bonds or higher dominance rank all lead longer lives. However, it remains unclear whether social environments also predict survival in male non-human primates, as it does in men. This gap persists because, in most primates, males disperse among social groups, resulting in many males who disappear with unknown fate and have unknown dates of birth. We present a Bayesian model to estimate the effects of time-varying social covariates on age-specific adult mortality in both sexes of wild baboons. We compare how the survival trajectories of both sexes are linked to social bonds and social status over the life. We find that, parallel to females, male baboons who are more strongly bonded to females have longer lifespans. However, males with higher dominance rank for their age appear to have shorter lifespans. This finding brings new understanding to the adaptive significance of heterosexual social bonds for male baboons: in addition to protecting the male's offspring from infanticide, these bonds may have direct benefits to males themselves. This article is part of the theme issue 'Evolution of the primate ageing process'.