Parochial altruism, defined as increased ingroup favoritism and heightened outgroup hostility, is a widespread feature of human societies that affects altruistic cooperation and punishment behavior, particularly in intergroup conflicts. Humans tend to protect fellow group members and fight against outsiders, even at substantial costs for themselves. Testosterone modulates responses to competition and social threat, but its exact role in the context of parochial altruism remains controversial. Here, we investigated how testosterone influences altruistic punishment tendencies in the presence of an intergroup competition. Fifty male soccer fans played an ultimatum game (UG), in which they faced anonymous proposers that could either be a fan of the same soccer team (ingroup) or were fans of other teams (outgroups) that differed in the degree of social distance and enmity to the ingroup. The UG was played in two contexts with varying degrees of intergroup rivalry. Our data show that unfair offers were rejected more frequently than fair proposals and the frequency of altruistic punishment increased with increasing social distance to the outgroups. Adding an intergroup competition led to a further escalation of outgroup hostility and reduced punishment of unfair ingroup members. High testosterone levels were associated with a relatively increased ingroup favoritism and also a change towards enhanced outgroup hostility in the intergroup competition. High testosterone concentrations further predicted increased proposer generosity in interactions with the ingroup. Altogether, a significant relation between testosterone and parochial altruism could be demonstrated, but only in the presence of an intergroup competition. In human males, testosterone may promote group coherence in the face of external threat, even against the urge to selfishly maximize personal reward. In that way, our observation refutes the view that testosterone generally promotes antisocial behaviors and aggressive responses, but underlines its rather specific role in the fine-tuning of male social cognition.