The evolution of mutualism between hosts and initially parasitic symbionts represents a major transition in evolution. Although vertical transmission of symbionts during host reproduction and partner control both favour the stability of mutualism, these mechanisms require specifically evolved features that may be absent during the transition. Therefore, the first steps of the transition from parasitism to mutualism are not fully understood. Spatial structure might be the key to this transition. We explore this hypothesis using a spatially explicit agent-based model. We demonstrate that, starting from a parasitic system with global dispersal, the coevolution between mutualistic effort and local dispersal of hosts and symbionts leads to a stable coexistence between parasites and mutualists. The local dispersal evolution mimics vertical transmission and triggers the formation of mutualistic clusters, counteracting the individual selection level of parasites that maintain global dispersal. However, the transition also requires competition between hosts in order to occur. Indeed, the transition occurs when mutualistic symbionts increase the density of hosts, which strengthens competition between hosts and disfavours parasitic host/symbiont pairs: mutualists create ecological conditions that allow their own spread. Therefore, the transition to mutualism may come from an eco-evolutionary feedback loop involving spatially structured population dynamics.