Sex is remarkably plastic in fish and can be easily influenced by environmental cues, in which temperature has been the most studied abiotic factor. However, it has been shown that elevated population densities can increase the number of males in several species but little is known about the underlying molecular mechanisms and whether general patterns exist. Here, we studied the long‐term effects of population density on the gene expression program in zebrafish gonads. The ovarian transcriptome of females exposed to high versus low population densities contained 4,634 differentially expressed genes. Among them, a set of promale genes (amh, sypc3, spata6, and sox3) were upregulated in the high‐population density group. Next, we compared the transcriptomes of ovaries of female zebrafish resistant to the masculinizing effects of either high density or elevated temperature. Results showed a set of 131 and 242 common upregulated and downregulated genes, respectively, including the upregulation of known male‐related genes (e.g., amh and sycp3) but also genes involved in other functions (e.g., faima, ccm21, and ankrd6b) and a downregulation of cyp19a1a together with other genes (e.g., lgals9l1 and ubxn2a). We identified the common Gene Ontology terms involved in the reproduction and sexual development that were consistently affected in both environmental factors. These results show that regardless of the environmental perturbation there are common genes and cellular functions involved in the resistance to masculinization. These altered gene‐expression profiles can be used as markers indicative of previous exposure to environmental stress independent of conspicuous alterations in sex ratios or gonadal morphology.