The availability of an ever-increasing diversity of prokaryotic genomes and metagenomes represents a major opportunity to understand and decipher the mechanisms behind the functional diversification of microbial biosynthetic pathways. However, it remains unclear to what extent a pathway producing a specific molecule from a specific precursor can diversify. In this study, we focus on the biosynthesis of ubiquinone (UQ), a crucial coenzyme that is central to the bioenergetics and to the functioning of a wide variety of enzymes in Eukarya and Pseudomonadota (a subgroup of the formerly named Proteobacteria). UQ biosynthesis involves three hydroxylation reactions on contiguous carbon atoms. We and others have previously shown that these reactions are catalysed by different sets of UQ-hydroxylases that belong either to the iron-dependent Coq7 family or to the more widespread flavin monooxygenase (FMO) family. Here, we combine an experimental approach with comparative genomics and phylogenetics to reveal how UQ-hydroxylases evolved different selectivities within the constrained framework of the UQ pathway. It is shown that the UQ-FMOs diversified via at least three duplication events associated with two cases of neo-functionalization and one case of sub-functionalization, leading to six sub-families with distinct hydroxylation selectivity. We also demonstrate multiple transfers of the UbiM enzyme and the convergent evolution of UQ-FMOs towards the same function, which resulted in two independent losses of the Coq7 ancestral enzyme. Diversification of this crucial biosynthetic pathway has therefore occurred via a combination of parallel evolution, gene duplications, transfers, and losses.