Summary Understanding the evolution of pathogen resistance genes (nucleotide‐binding site‐leucine‐rich repeats, NLRs) within a species requires a comprehensive examination of factors that affect gene loss and gain. We present a new reference genome of Solanum chilense , which leads to an increased number and more accurate annotation of NLRs. Using a target capture approach, we quantify the presence–absence variation (PAV) of NLR loci across 20 populations from different habitats. We build a rigorous pipeline to validate the identification of PAV of NLRs and then show that PAV is larger within populations than between populations, suggesting that maintenance of NLR diversity is linked to population dynamics. The amount of PAV appears not to be correlated with the NLR presence in gene clusters in the genome, but rather with the past demographic history of the species, with loss of NLRs in diverging (smaller) populations at the distribution edges. Finally, using a redundancy analysis, we find limited evidence of PAV being linked to environmental gradients. Our results suggest that random processes (genetic drift and demography) and weak positive selection for local adaptation shape the evolution of NLRs at the single nucleotide polymorphism and PAV levels in an outcrossing plant with high nucleotide diversity.