Oviparous, facultative egg retention enables Drosophila females to withhold fertilized eggs in their reproductive tracts until circumstances favor oviposition. The propensity to retain fertilized eggs varies greatly between species, and is correlated with other reproductive traits, such as egg size and ovariole number. While previous studies have described the phenomenon, no study to date has characterized within-species variation or the genetic basis of the trait. Here, we develop a novel microscope-based method for measuring egg retention in Drosophila females and determine the range of phenotypic variation in mated female egg retention in a subset of 91 Drosophila Genetic Reference Panel (DGRP) lines. We inferred the genetic basis of egg retention using a genome-wide association study (GWAS). Further, the scoring of more than 95,000 stained, staged eggs enabled estimates of fertilization success for each line. We found evidence that ovary- and spermathecae-related genes as well as genes affecting olfactory behavior, male mating behavior, male-female attraction and sperm motility may play a crucial role in post-mating physiology. Based on our findings we also propose potential evolutionary routes toward obligate viviparity. In particular, we propose that the loss of fecundity incurred by viviparity could be offset by benefits arising from enhanced mate discrimination, resource specialization, or modified egg morphology.