Local adaptation to contrasting environmental conditions along environmental gradients is a widespread phenomenon in plant populations, yet we lack a mechanistic understanding of how individual agents of selection contribute to this evolutionary process. Here, we developed a novel evolutionary functional-structural plant (E-FSP) model that recreates local adaptation of virtual plants along an environmental gradient. First, we validate the model by testing if it can reproduce two elevational ecotypes of Dianthus carthusianorum occurring in the Swiss Alps. Second, we use the E-FSP model to disentangle the relative contribution of abiotic (temperature) and biotic (competition and pollination) selection pressures to elevational adaptation in D. carthusianorum. Our results suggest that elevational adaptation in D. carthusianorum is predominantly driven by the abiotic environment. The model reproduced the qualitative differences between the elevational ecotypes in two phenological (germination and flowering time) and one morphological trait (stalk height), as well as qualitative differences in four performance variables that emerge from G × E interactions (flowering time, number of stalks, rosette area and seed production). Our approach shows how E-FSP models incorporating physiological, ecological and evolutionary mechanisms can be used in combination with experiments to examine hypotheses about patterns of adaptation observed in the field.