Many mammal populations show significant deviations from an equal sex ratio at birth, but these effects are notoriously inconsistent. This may be because more than one mechanism affects the sex ratio and the action of these mechanisms depends on environmental conditions. Here we show that the adaptive relationship between maternal dominance and offspring sex ratio previously demonstrated in red deer (Cervus elaphus), where dominant females produced more males, disappeared at high population density. The proportion of males born each year declined with increasing population density and with winter rainfall, both of which are environmental variables associated with nutritional stress during pregnancy. These changes in the sex ratio corresponded to reductions in fecundity, suggesting that they were caused by differential fetal loss. In contrast, the earlier association with maternal dominance is presumed to have been generated pre-implantation. The effects of one source of variation superseded the other within about two generations. Comparison with other ungulate studies indicates that positive associations between maternal quality and the proportion of male offspring born have only been documented in populations below carrying capacity.