Sexually selected traits may also be subject to non‐sexual selection. If optimal trait values depend on environmental conditions, then “narrow sense” (i.e., non‐sexual) natural selection can lead to local adaptation, with fitness in a certain environment being highest among individuals selected under that environment. Such adaptation can, in turn, drive ecological speciation via sexual selection. To date, most research on the effect of narrow‐sense natural selection on sexually selected traits has focused on precopulatory measures like mating success. However, postcopulatory traits, such as sperm function, can also be under non‐sexual selection, and have the potential to contribute to population divergence between different environments. Here, we investigate the effects of narrow‐sense natural selection on male postcopulatory success in Drosophila melanogaster. We chose two extreme environments, low oxygen (10%, hypoxic) or high CO2 (5%, hypercapnic) to detect small effects. We measured the sperm defensive (P1) and offensive (P2) capabilities of selected and control males in the corresponding selection environment and under control conditions. Overall, selection under hypoxia decreased both P1 and P2, while selection under hypercapnia had no effect. Surprisingly, P1 for both selected and control males was higher under both ambient hypoxia and ambient hypercapnia, compared to control conditions, while P2 was lower under hypoxia. We found limited evidence for local adaptation: the positive environmental effect of hypoxia on P1 was greater in hypoxia‐selected males than in controls. We discuss the implications of our findings for the evolution of postcopulatory traits in response to non‐sexual and sexual selection.