The repeated evolutionary transition from outcrossing to self-pollination in flowering plants has been suggested to occur because selfing provides reproductive assurance. Reports from biogeographical and ecological surveys indicate that selfing taxa are often associated with stressful and ephemeral environments, situations in which plant abundance is low (e.g., Baker's law) and with novel plant communities, however experimental tests of ecological hypotheses are few. In this study, we examined the ecological context of selection on mating system traits (herkogamy and protandry) in a California annual, Clarkia xantiana, where natural selfing populations differ from outcrossing populations in that they are often of small size or low density and occur mainly outside the range of pollinator-sharing congeners. We constructed artificial populations of plants with broad genetic variation in floral traits and manipulated two ecological factors, plant population size, and the presence versus absence of pollinator-sharing congeners, in the center of the geographic range of outcrossing populations. We found evidence for context-dependent selection on herkogamy and protandry via female fitness in which reduced traits, which promote autonomous selfing, were favored in small populations isolated from congeners whereas selection was comparatively weak in large populations or when congeners were present. In small, isolated populations, the fertility of plants with low herkogamy or protandry was elevated by 66% and 58%, respectively, compared to those with high herkogamy or protandry. The presence of pollinator-sharing congeners augmented bee visitation rates to C. xantiana flowers by 47% for all bees and by 93% for pollen specialists. By facilitating pollinator visitation, congeners mitigated selection on mating system traits in small populations, where outcross mating success is often low (the Allee effect). We also found support for the hypothesis that pollinator availability directly influenced variation in the strength of selection on herkogamy among populations. The striking parallels between our experimental results and patterns of variation in ecological factors across the geographic range of outcrossing and selfing populations suggest that reproductive assurance may play a central role in directing mating system evolution in C. xantiana.