Fungi contain a remarkable diversity of both primary and secondary metabolic pathways involved in ecologically specialized or accessory functions. Genes in these pathways are frequently physically linked on fungal chromosomes, forming metabolic gene clusters (MGCs). In this Review, we describe the diversity in the structure and content of fungal MGCs, their population-level and species-level variation, the evolutionary mechanisms that underlie their formation, maintenance and decay, and their ecological and evolutionary impact on fungal populations. We also discuss MGCs from other eukaryotes and the reasons for their preponderance in fungi. Improved knowledge of the evolutionary life cycle of MGCs will advance our understanding of the ecology of specialized metabolism and of the interplay between the lifestyle of an organism and genome architecture.