Dark ecosystems such as caves are assumed to be oligotrophic in the absence of external subsidies, with insufficient energy sources to support complex life. Yet surveys of unsubsidised caves have revealed extensive microbial communities inhabiting soils, sediments and mineral surfaces. Lacking obvious routes for primary production, the energetic basis for these communities remains a mystery. Combining metagenomics, biogeochemical activity measurements, and thermodynamic models, we uncover the vital role of atmospheric hydrogen, carbon monoxide, and methane in sustaining microbial biodiversity and growth. We show that aerobic methanotrophs are sufficiently active and enriched in these ecosystems to act as major primary producers. Microbial capabilities for using inorganic energy from ammonium, nitrite, and sulfide are active, but inferred to be subservient processes overall. Our results demonstrate that caves comprise a constantly active chemosynthetic environment that is fuelled by atmospheric energy.