Many nonhuman animals preferentially copy the actions of others when the environment contains predation risk or other types of danger. In humans, the role of social learning in avoidance of danger is still unknown, despite the fundamental importance of social learning for complex social behaviors. Critically, many social behaviors, such as cooperation and adherence to religious taboos, are maintained by threat of punishment. However, the psychological mechanisms allowing threat of punishment to generate such behaviors, even when actual punishment is rare or absent, are largely unknown. To address this, we used both computer simulations and behavioral experiments. First, we constructed a model where simulated agents interacted under threat of punishment and showed that mechanisms' (a) tendency to copy the actions of others through social learning, together with (b) the rewarding properties of avoiding a threatening punishment, could explain the emergence, maintenance, and transmission of large-scale behavioral traditions, both when punishment is common and when it is rare or nonexistent. To provide empirical support for our model, including the 2 mechanisms, we conducted 4 experiments, showing that humans, if threatened with punishment, are exceptionally prone to copy and transmit the behavior observed in others. Our results show that humans, similar to many nonhuman animals, use social learning if the environment is perceived as dangerous. We provide a novel psychological and computational basis for a range of human behaviors characterized by the threat of punishment, such as the adherence to cultural norms and religious taboos.