Past research shows that ethnic diversity reduces the ability to sanction norm violators, ultimately undermining cooperation. We test this directly by experimentally varying the ethnic composition of groups playing a dictator game with third-party punishment among two ethnic groups along the Kenya–Tanzania border. We also implement a structurally identical game where the endowment division is randomly determined in order to isolate a punishment motivation from the motivation to rectify income inequality. While costly income adjustment in both games is driven primarily by norm violations and inequality aversion, the ethnic composition of groups also influences sharing and sanctioning behavior in Kenya but not Tanzania, consistent with documented differences in the strength of nationalism across the two countries. However, the way in which shared ethnicity affects sanctioning in Kenya—namely, increased punishment of out-group violations against in-group members—is at odds with theories that anticipate that costly sanctioning will primarily target coethnics.