Fitness-related life history traits often show substantial heritable genetic variation in natural populations, but knowledge of the genetic architecture of these traits is limited. In the Glanville fritillary butterfly, we measured the heritability of key life history traits in a large outdoor population cage during 2 years and generations and combined this experiment with an association study of a set of candidate genes. The genes were selected on the basis of previous genomic and transcriptomic studies and have been linked to the physiology and life history of this or other arthropod species. Heritability was high and significant for two traits, post-diapause larval development time (h2 = 0.37) and lifetime egg (and larval) production (h2 = 0.62); the latter is closely related to lifetime reproductive success and therefore fitness. We discovered a strong association between genetic polymorphism in the cytochrome P450 gene CYP337 and lifetime egg production, which accounted for 14% of the additive variance in egg production. This gene belongs to a group of cytochrome P450 genes that have a well-documented role in host plant adaptations in Lepidoptera and other insects and is likely to play an important role in the ecology and microevolution of the Glanville fritillary. This study provides a prime example of a gene associated with heritable fitness variation, measured under semi-natural ecological conditions.