Symbiosis between legumes and nitrogen-fixing bacteria is thought to bring mutual benefit to each participant. However, it is not known how rhizobia benefit from nodulation of legume hosts because they fix nitrogen only after differentiating into bacteroids, terminally differentiated cells that cannot reproduce. Because free-living rhizobia can reproduce, and may benefit from the increase of plant root exudates stimulated by nodulation, evolution of symbiotic nitrogen fixation may depend upon kin selection. However, unrelated nonmutualists may also benefit from increased plant exudates and nitrogen-fixing populations are therefore vulnerable to invasion by nonfixing, saprophytic Rhizobium. The access of nonfixing Rhizobium to the plant exudates associated with nodules depends upon the spatial structure of the Rhizobium populations within the soil. We investigate the influence of spatial structure on the evolution of N-fixation within a Rhizobium population using a mathematical model. Our model demonstrates that spatial structure is necessary for the evolution of N-fixation and that N-fixation is more likely to evolve with increasing degrees of spatial structure. In fact, we identify three dynamic outcomes that depend upon the relative strength of the costs of N-fixation relative to the degree of spatial structure and benefits resulting from nodulations. If the costs are relatively high, N-fixation will not evolve; if the costs are relatively low, N-fixing genes will fix in the population, but at intermediate conditions, a stable mixture of N-fixing bacteria and nonfixing bacteria will be maintained. The conditions for coexistence of N-fixing bacteria and nonfixing bacteria expand under a saturating relationship between nodule numbers and N-fixing genotype frequency.