Sexual selection promotes traits that enhance mating or fertilization success, but these traits can be very costly under harsh environmental conditions. The extent to which differential investment in costly traits under varying intensities of sexual selection is related to their susceptibility to environmental stress remains unclear. This study explored how experimental evolution under different operational sex ratios (OSRs) shapes traits and reproductive success of male Drosophila prolongata, and how developmental and/or adult heat stress affect the expression of these traits. We found males from even and slightly male-biased OSRs to be larger and display greater reduction in body size under developmental heat stress, suggesting pre-mating sexual selection on body size and condition-dependent thermal sensitivity. These populations also exhibited consistently high mating and fertilization success across temperatures, potentially indicating selection for robust phenotypes with 'good genes' that perform well regardless of temperature. Conversely, males from strongly male-biased OSR populations experienced more pronounced decline in sperm competitiveness following exposure to developmental or adult heat stress. These results highlight how environmental stressors differentially impact populations, shaped by varying strengths of pre- and post-mating sexual selection. These observed patterns suggest potential interactions between past selection and the ability to adapt to changing environments.