Unlike most species, humans cooperate extensively with group members who are not closely related to them, a pattern sustained in part by punishing non-cooperators and rewarding cooperators. Because internally cooperative groups prevail over less cooperative rival groups, it is thought that violent intergroup conflict played a key role in the evolution of human cooperation. Consequently, it is plausible that propensities to punish and reward will be elevated during intergroup conflict. Using experiments conducted before, during and after the 2006 Israel-Hezbollah war, we show that, during wartime, people are more willing to pay costs to punish non-cooperative group members and reward cooperative group members. Rather than simply increasing within-group solidarity, violent intergroup conflict thus elicits behaviours that, writ large, enhance cooperation within the group, thereby making victory more likely.