Bacteria and archaea are characterized by an amazing metabolic diversity, which allows them to persist in diverse and often extreme habitats. Apart from oxygenic photosynthesis and oxidative phosphorylation, well-studied processes from chloroplasts and mitochondria of plants and animals, prokaryotes utilize various chemo- or lithotrophic modes, such as anoxygenic photosynthesis, iron oxidation and reduction, sulfate reduction, and methanogenesis. Most bioenergetic pathways have a similar general structure, with an electron transport chain composed of protein complexes acting as electron donors and acceptors, as well as a central cytochrome complex, mobile electron carriers, and an ATP synthase. While each pathway has been studied in considerable detail in isolation, not much is known about their relative evolutionary relationships. Wanting to address how this metabolic diversity evolved, we mapped the distribution of nine bioenergetic modes on a phylogenetic tree based on 16S rRNA sequences from 272 species representing the full diversity of prokaryotic lineages. This highlights the patchy distribution of many pathways across different lineages, and suggests either up to 26 independent origins or 17 horizontal gene transfer events. Next, we used comparative genomics and phylogenetic analysis of all subunits of the F0F1 ATP synthase, common to most bacterial lineages regardless of their bioenergetic mode. Our results indicate an ancient origin of this protein complex, and no clustering based on bioenergetic mode, which suggests that no special modifications are needed for the ATP synthase to work with different electron transport chains. Moreover, examination of the ATP synthase genetic locus indicates various gene rearrangements in the different bacterial lineages, ancient duplications of atpI and of the beta subunit of the F0 subcomplex, as well as more recent stochastic lineage-specific and species-specific duplications of all subunits. We discuss the implications of the overall pattern of conservation and flexibility of the F0F1 ATP synthase genetic locus.