The difficulty of avoiding dangerous climate change arises from a tension between group and self-interest1,2,3 and is exacerbated by climate change’s intergenerational nature4. The present generation bears the costs of cooperation, whereas future generations accrue the benefits if present cooperation succeeds, or suffer if present cooperation fails. Although temporal discounting has long been known to matter in making individual choices5, the extent of temporal discounting is poorly understood in a group setting. We represent the effect of both intra- and intergenerational discounting4,6,7 through a collective-risk group experiment framed around climate change. Participants could choose to cooperate or to risk losing an additional endowment with a high probability. The rewards of defection were immediate, whereas the rewards of cooperation were delayed by one day, delayed by seven weeks (intragenerational discounting), or delayed by several decades and spread over a much larger number of potential beneficiaries (intergenerational discounting). We find that intergenerational discounting leads to a marked decrease in cooperation; all groups failed to reach the collective target. Intragenerational discounting was weaker by comparison. Our results experimentally confirm that international negotiations to mitigate climate change are unlikely to succeed if individual countries’ short-term gains can arise only from defection.