As wildlife is increasingly affected by environmental change, identifying how vital rates vary with ecological factors is essential to predict the consequences of environmental perturbations on wild population dynamics. We explored the effects of habitat constraints on the demographic and life history patterns of two Barbary macaque (Macaca sylvanus) populations living in two contrasted habitats in Algeria. Using 11 years of field data, we estimated age‐specific survival rates of females and of infants of both sexes, as well as female reproduction rates. We investigated how these vital rates were influenced by both intra‐ and inter‐habitat environmental variations. We parameterized age‐structured female‐only transition matrices and conducted a prospective analysis to estimate the contribution of each vital rate to the populations' asymptotic growth rates (λ). A retrospective analysis (LTRE, Life Table Response Experiment) was also conducted to determine how each vital rate contributed to the observed differences in λ between populations. The macaques exhibited common patterns of survival and reproduction (low rates at young ages, and then high and stable until a decrease at old ages), with first evidence of both actuarial and reproductive senescence. Both populations were growing. In both populations, adult and immature survival had the highest elasticities, and remained stable in changing environmental conditions. By contrast, infant survival and female reproduction had low elasticities, and varied more with environmental variations. As Barbary macaque habitats are increasingly degrading, we provide robust estimates of their vital rates with conservation implications, in particular to predict population responses to anthropogenic perturbations.