In socially monogamous species, extra-pair paternity may increase the strength of intersexual selection by allowing males with preferred phenotypes to monopolize matings. Several studies have found relationships between male signals and extra-pair mating, but many others fail to explain variation in extra-pair mating success. A greater appreciation for the role that ecological contingencies play in structuring behavioural processes may help to reconcile contradictory results. We studied extra-pair mating in a spatial context in the common yellowthroat (Geothlypis trichas), a territorial wood warbler. Over the course of 6 years, we observed 158 breeding attempts by 99 males, resulting in a total of 369 nests and 520 sampled nestlings. The spatial distribution of territories varied greatly, with males having between 0 and 10 close neighbours and between three and 39 neighbouring nestlings close enough to represent extra-pair siring opportunities. Both within-pair and extra-pair reproductive success increased with breeding density, but the opportunity for sexual selection and strength of selection varied with density. Total variance in reproductive success was highest at low density and was mostly explained by variation in within-pair success. In contrast, at high density, both within-pair and extra-pair successes contributed substantially to variance in reproductive success. The relationships between plumage and extra-pair mating also varied by density; plumage was under strong sexual selection via extra-pair mating success at high density, but no selection was detected at low density. Thus, ecological factors that structure social interactions can drive patterns of sexual selection by facilitating or constraining the expression of mating preferences.