This experiment investigated potential gender biases in the emergence of leadership in groups. Teams played a public-goods game under conditions of intra- or intergroup competition. We predicted and found a strong preference for female leaders during intragroup competition and male leaders during intergroup competition. Furthermore, during intragroup competition, a female leader was more instrumental than a male leader in raising group investments, but this pattern was reversed during intergroup competition. These findings suggest that particular group threats elicit specific gender-biased leader prototypes. We speculate about the evolutionary and cultural origins of these sex differences in the emergence of leadership.