The discovery of major axes of correlated functional variation among species and habitats has revealed the fundamental trade-offs structuring both functional and taxonomic diversity in eukaryotes such as plants. Whether such functional axes exist in the bacterial realm and whether they could explain bacterial taxonomic turnover among ecosystems remains unknown. Here, we use a data-driven approach to leverage global genomic and metagenomic datasets to reveal the existence of major axes of functional variation explaining both evolutionary differentiation within Bacteria and their ecological sorting across diverse habitats. We show that metagenomic variation among bacterial communities from various ecosystems is structured along a few axes of correlated functional pathways. Similar clusters of traits explained phylogenetic trait variation among >16,000 bacterial genomes, suggesting that functional turnover among bacterial communities from distinct habitats does not only result from the differential filtering of similar functions among communities, but also from phylogenetic correlations among these functions. Concordantly, functional pathways associated with trait clusters that were most important for defining functional turnover among bacterial communities were also those that had the highest phylogenetic signal in the bacterial genomic phylogeny. This study overall underlines the important role of evolutionary history in shaping contemporary distributions of bacteria across ecosystems.