Understanding the variation in selection pressure on key life-history traits is crucial in our rapidly changing world. Density is rarely considered as a selective agent. To study its importance, we partition phenotypic selection in fluctuating environments into components representing the population growth rate at low densities and the strength of density dependence, using a new stochastic modelling framework. We analysed the number of eggs laid per season in a small song-bird, the great tit, and found balancing selection favouring large clutch sizes at small population densities and smaller clutches in years with large populations. A significant interaction between clutch size and population size in the regression for the Malthusian fitness reveals that those females producing large clutch sizes at small population sizes also are those that show the strongest reduction in fitness when population size is increased. This provides empirical support for ongoing r- and K-selection in this population, favouring phenotypes with large growth rates r at small population sizes and phenotypes with high competitive skills when populations are close to the carrying capacity K. This selection causes long-term fluctuations around a stable mean clutch size caused by variation in population size, implying that r- and K-selection is an important mechanism influencing phenotypic evolution in fluctuating environments. This provides a general link between ecological dynamics and evolutionary processes, operating through a joint influence of density dependence and environmental stochasticity on fluctuations in population size.