Development of human societies requires cooperation among unrelated individuals and obedience to social norms. Although punishment is widely agreed to be potentially useful in fostering cooperation, many recent results in psychology and economics highlight punishments' failures in this regard. These studies ignore punishments' social effects, and particularly its role in promoting social norms. We show here, using experiments with human subjects, that public implementation of punishment can eliminate its detrimental effects on cooperation. In a public goods game designed to create tension between group and individual interests, we find that privately implemented punishment reduces cooperation relative to a baseline treatment without punishment. However, when that same incentive is implemented publicly, but anonymously, cooperation is sustained at significantly higher rates than in both baseline and private punishment treatments. These data support our hypothesis that public implementation of punishment enhances the salience of the violated social norm to both the punished and those who observed the punishment, and that this increased salience positively affects group members' norm obedience. Our findings point to the importance of accounting for social consequences of punishment when designing procedures to deter misconduct in social environments including schools, companies, markets and courts.