In small populations of plant species with separate sexes, it can be expected that besides the local environment also stochastic events influence population sex ratios. Biased sex ratios may in turn negatively affect genetic diversity due to increased genetic drift and, in clonal plants, due to reduced sexual reproductive output. Empirical evidence for these processes is scarce, however. We investigated the pattern of sex ratio variation and the distribution of genetic variation of the dioecious clonal forest herb Mercurialis perennis using AFLP markers. Analysis of molecular variance indicated a pronounced genetic structure. Overall within-population genetic diversity was moderate and local sex ratios were slightly male biased. The proportion of male to female plants in large populations slightly increased with increasing light penetration to the herb layer. Small populations, on the contrary, displayed high variability in sex ratios, unrelated to the local light environment. Genotypic diversity decreased with more male-biased sex ratios. We conclude that stochastic events related to small population size and the local forest environment, related to canopy closure, affect the proportion of female plants and indirectly influence local genotypic diversity, likely through the degree of sexual reproduction. This is one of the first studies to report a clear association between gender proportions and genetic diversity of a dioecious plant species in a fairly large survey.