Conservation areas encompassing elevation gradients are biodiversity hotspots because they contain a wide range of habitat types in a relatively small space. Studies of biodiversity patterns along elevation gradients, mostly on small mammal or bird species, have documented a peak in diversity at mid elevations. Here, we report on a field study of medium and large mammals to examine the impact of elevation, habitat type, and gross primary productivity on community structure. Species richness was observed using a camera trap transect with 219 sites situated across different habitat types from 2329 to 4657 m above the sea level on the western slope of Mt Kenya, the second highest mountain in Africa. We found that the lowest elevation natural habitats had the highest species richness and relative abundance and that both metrics decreased steadily as elevation increased, paralleling changes in gross primary productivity, and supporting the energy richness hypothesis. We found no evidence for the mid‐domain effect on species diversity. The lowest elevation degraded Agro‐Forestry lands adjacent to the National Park had high activity of domestic animals and reduced diversity and abundance of native species. The biggest difference in community structure was between protected and unprotected areas, followed by more subtle stepwise differences between habitats at different elevations. Large carnivore species remained relatively consistent but dominant herbivore species shifted along the elevation gradient. There was some habitat specialization and turnover in species, such that the elevation gradient predicts a high diversity of species, demonstrating the high conservation return for protecting mountain ecosystems for biodiversity conservation.