Biofilms are spatially structured communities of microbes whose function is dependent on a complex web of symbiotic interactions1,2. Localized interactions within these assemblages are predicted to affect the coexistence of the component species3-5, community structure6and function7-10, but there have been few explicit empirical analyses of the evolution of interactions11. Here we show, with the use of a two-species community, that selection in a spatially structured environment leads to the evolution of an exploitative interaction. Simple mutations in the genome of one species caused it to adapt to the presence of the other, forming an intimate and specialized association. The derived community was more stable and more productive than the ancestral community. Our results show that evolution in a spatially structured environment can stabilize interactions between species, provoke marked changes in their symbiotic nature and affect community function.