The social good often depends on the altruistic behavior of specific individuals. For example, epidemiological studies of influenza indicate that elderly individuals, who face the highest mortality risk, are best protected by vaccination of young individuals, who contribute most to disease transmission. To examine the conditions under which young people would get vaccinated to protect elderly people, we conducted a game-theory experiment that mirrored real-world influenza transmission, with "young" players contributing more than "elderly" players to herd immunity. Participants could spend points to get vaccinated and reduce the risk of influenza. When players were paid according to individual point totals, more elderly than young players got vaccinated, a finding consistent with the Nash equilibrium predicting self-interested behavior. When players were paid according to group point totals, however, more young than elderly players got vaccinated-a finding consistent with the utilitarian equilibrium predicting group-optimal behavior-which resulted in higher point totals than when players were paid for their individual totals. Thus, payout structure affected whether individuals got vaccinated for self-interest or group benefit.