Horizontal gene transfer (HGT) is considered a major source of innovation in bacteria, and as such is expected to drive the adaptation to new ecological niches. However, among the many genes acquired through HGT along the diversification history of genomes, only a fraction may have actively contributed to sustained ecological adaptation. Here, we implement a reverse ecology approach, involving the phylogenetic reconstruction of the evolutionary history of the pangenome within a bacterial clade and the modelling of the HGT process to recognize adaptive gene gains. We apply it to Agrobacterium biovar 1, a diverse group of soil and plant-dwelling bacterial species. We identify synapomorphic gene gains for major clades and show that most are organized into blocks of co-transferred genes encoding coherent biochemical pathways. This pattern of gene co-evolution rejects a neutral model of transfer, in which neighbouring genes would be transferred independently of their function. Instead, the conservation of acquired genes appears driven by purifying selection on collectively coded functions. We therefore propose synapomorphic blocks of co-functioning genes as candidate determinants of ecological adaptation of each clade. Their inferred biochemical functions define features of ancestral ecological niches, which consistently hint at the strong selective role of host plant rhizospheres.