Ecological communities are commonly thought to be controlled by the dynamics of energy flow through environments. Two of the most important energetic constraints on all communities are photosynthetically active radiation (PAR) and oxygen concentration ([O 2 ]). Microbial mats growing on the bottom of Lake Fryxell, Antarctica, span environmental gradients in PAR and [O 2 ], which we used to test the extent to which each controls community structure. Metagenomic analyses showed variation in the diversity and relative abundances of Archaea, Bacteria, and Eukaryotes across three [O 2 ] and PAR conditions. Where [O 2 ] saturated the mats or was absent from the overlying water, PAR structured the community. Where [O 2 ] varied within mats, microbial communities changed across covarying PAR and [O 2 ] gradients. Diversity negatively correlated with [O 2 ] and PAR through mat layers in each habitat suggesting that, on the millimeter-scale, communities are structured by the optimization of energy use. In contrast, [O 2 ] positively correlated with diversity and affected the distribution of dominant populations across the three habitats, suggesting that meter-scale diversity is structured by energy availability. The benthic microbial communities in Lake Fryxell are thus structured by energy flow in a scale-dependent manner.