Predicting and managing contemporary adaption requires a proper understanding of the determinants of genetic variation. Spatial heterogeneity of the environment may stably maintain polymorphism when habitat contribution to the next generation can be considered independent of the degree of adaptation of local populations within habitats (i.e., under soft selection). In contrast, when habitats contribute proportionally to the mean fitness of the populations they host (hard selection), polymorphism is not expected to be maintained by selection. Although mathematically established decades ago, this prediction had never been properly tested. Here we provide an experimental test in which polymorphic populations of Escherichia coli growing in heterogeneous habitats were exposed to hard and soft selection regimes. As predicted by theory, polymorphism was longer preserved in asymmetric environments under soft selection. Complementary tests established that soft selection actually protected polymorphism even when one genotype was present at low frequency.