Metabolic cross-feeding interactions are ubiquitous in natural microbial communities. However, it remains generally unclear whether the production and exchange of metabolites incurs fitness costs to the producing cells and if so, which ecological mechanisms can facilitate a cooperative exchange of metabolites among unrelated individuals. We hypothesized that positive assortment within structured environments can maintain mutualistic cross-feeding. To test this, we engineered Acinetobacter baylyi and Escherichia coli to reciprocally exchange essential amino acids. Interspecific coculture experiments confirmed that non-cooperating types were selectively favoured in spatially unstructured (liquid culture), yet disfavoured in spatially structured environments (agar plates). Both an individual-based model and experiments with engineered genotypes indicated that a segregation of cross-feeders and non-cooperating auxotrophs stabilized cooperative cross-feeding in spatially structured environments. Chemical imaging confirmed that auxotrophs were spatially excluded from cooperative benefits. Together, these results demonstrate that cooperative cross-feeding between different bacterial species is favoured in structured environments such as bacterial biofilms, suggesting this type of interactions might be common in natural bacterial communities.