Two distinct forms of natural selection promote adaptive biological diversity. Divergent selection occurs when different environments favour different phenotypes, leading to increased differences between populations1. Negative frequency-dependent selection occurs when rare variants within a population are favoured over common ones2, increasing diversity within populations3. These two diversifying forces promote genetic variation at different spatial scales, and may act in opposition, but their relative effects remain unclear because they are rarely measured concurrently. Here we show that negative frequency-dependent selection within populations can favor rare immigrants over locally adapted residents. We reciprocally transplanted lake and stream ecotypes of threespine stickleback4 into lake and stream habitats, while manipulating the relative abundance of residents versus immigrants. We found negative frequency-dependence: survival was highest for the locally rare ecotype, rather than natives. Also, individuals with locally rare major histocompatibility complex (MHC) class IIb genotypes were infected by fewer parasites. This negative frequency-dependent selection will tend to favour rare immigrants over common residents, amplifying the effect of migration and undermining the efficacy of divergent natural selection to drive population differences. The only signal of divergent selection was a tendency for foreign fish to have higher parasite loads than residents, after controlling for MHC genotype rarity. Frequency-dependent ecological interactions have long been thought to promote speciation. Our results suggest a more nuanced view in which negative frequency dependence alters the fate of migrants to promote or constrain evolutionary divergence between populations.