In dioecious plants, males and females frequently show 'leaky' sex expression, with individuals occasionally producing flowers of the opposite sex. This leaky sex expression may have enabled the colonization of oceanic islands by dioecious plant species, and it is likely to represent the sort of variation upon which selection acts to bring about evolutionary transitions from dioecy to hermaphroditism. Although leakiness is commonly reported for dioecious species, it is not known whether it has plastic component. The question is interesting because males or females with an ability to enhance their leakiness plastically in the absence of mates would have an advantage of being able to produce progeny by self-fertilization. Here, we demonstrate that leaky sex expression in the wind-pollinated dioecious herb Mercurialis annua is plastically responsive to its mating context. We compared experimental populations of females growing either with or without males. Females growing in the absence of males were leakier in their sex expression than controls growing with males, producing more than twice as many male flowers. Our results thus provide a striking instance of plasticity in the reproductive behaviour of plants that is likely adaptive. We consider how females might sense their mating environment as a function of pollen availability, and we discuss possible constraints on the evolution of plasticity in sex expression when the environmental signals that individuals receive are unreliable. © 2020 The Authors. Journal of Evolutionary Biology published by John Wiley & Sons Ltd on behalf of European Society for Evolutionary Biology.