Bacterial communities are taxonomically highly diverse, yet the mechanisms that maintain this diversity remain poorly understood. We hypothesized that an obligate and mutual exchange of metabolites, as is very common among bacterial cells, could stabilize different genotypes within microbial communities. To test this, we developed a cellular automaton to model interactions among six empirically characterized genotypes that differ in their ability and propensity to produce amino acids. By systematically varying intrinsic (i.e. benefit-to-cost ratio) and extrinsic parameters (i.e. metabolite diffusion level, environmental amino acid availability), we show that obligate cross-feeding of essential metabolites is selected for under a broad range of conditions. In spatially structured environments, positive assortment among cross-feeders resulted in the formation of cooperative clusters, which limited exploitation by non-producing auxotrophs, yet allowed them to persist at the clusters periphery. Strikingly, cross-feeding helped to maintain genotypic diversity within populations, while amino acid supplementation to the environment decoupled obligate interactions and favored auxotrophic cells that saved amino acid production costs over metabolically autonomous prototrophs. Together, our results suggest that spatially structured environments and limited nutrient availabilities should facilitate the evolution of metabolic interactions, which can help to maintain genotypic diversity within natural microbial populations.