Environments that are crowded with larvae of the fruit fly, Drosophila melanogaster, exhibit a temporal deterioration in quality as waste products accumulate and food is depleted. We show that natural selection in these environments can maintain a genetic polymorphism with one group of genotypes specializing on the early part of the environment and a second group specializing on the late part. These specializations involve trade-offs in fitness components. The early types emerge first from crowded cultures and have high larval feeding rates, which are positively correlated with competitive ability but exhibit lower absolute viability than the late phenotype, especially in food contaminated with the nitrogenous waste product, ammonia. The late emerging types have reduced feeding rates but higher absolute survival under conditions of severe crowding and high levels of ammonia. Organisms that experience temporal variation within a single generation are not uncommon, and this model system provides some of the first insights into the evolutionary forces at work in these environments.