In many social birds there are sex differences in dispersal patterns, with males commonly remaining in their natal group whereas females typically disperse at adolescence. Group members may therefore increase their fitness by preferentially caring for offspring of a particular sex according to social circumstances. Although previous studies have focussed on intragroup social factors that may affect preferential care, we propose that the relative size of neighbouring groups is of primary importance. Here we show that in the cooperatively breeding Arabian babbler (Turdoides squamiceps), parents preferentially feed male offspring when relative group size is small, and female offspring when group size is large. Unlike parents, helpers consistently favour young of the opposite sex to themselves, suggesting the risk of competition with members of the same sex for future breeding opportunities may override other considerations. These results emphasize the complexity of investment strategies in relation to social circumstances and the variable benefits of raising males vs. females in a species with sex-biased philopatry.