Barbary macaques live in extreme temperate environments characterized by strongly seasonal resource availability. They are mainly terrestrial while foraging, harvesting food from the herbaceous layer. These monkeys are threatened mainly because of anthropogenic habitat degradation. We studied the adaptive capacities of wild groups of Barbary macaques that lived in different cedar forests undergoing varying extents of grazing pressure from domestic livestock. In all three sites, diet varied seasonally. Heavy grazing led to a significant decrease in herbaceous production and species richness. As a consequence, the monkeys' diet in this poor habitat showed a decreased plant species richness. Moreover, it incorporated fewer above-ground herbaceous resources, and a greater proportion of subterranean resources (especially hypogeous fungi and subterranean invertebrates such as earthworms, eggs and adults of earwigs, and ant's larvae) than the diet of monkeys inhabiting ungrazed forest. Cedar bark, cedar strobiles, earthworms, and earwigs were part of the monkeys' diet only in grazed forest. Monkeys in heavily grazed forest compensated for a lack of herbaceous foods by eating subterranean foods preferentially to tree and shrub products. The foods they consumed take longer to harvest and process than the seeds or leaves consumed by Barbary macaques in less heavily grazed forest habitats. Our results suggest that monkeys do differ in their diets according to the degree of habitat change induced by human activities. They also highlight the dietary flexibility of Barbary macaques as a key element that allows them to cope with degraded habitats. We later compare the dietary adjustments of Barbary macaques facing environmental change to dietary strategies of other macaques and temperate-zone primates. Am. J. Primatol. 76:679–693, 2014. © 2014 Wiley Periodicals, Inc.