The evolution of altruism-costly self-sacrifice in the service of others-has puzzled biologists since The Origin of Species. For half a century, attempts to understand altruism have developed around the concept that altruists may help relatives to have extra offspring in order to spread shared genes. This theory-known as inclusive fitness-is founded on a simple inequality termed Hamilton's rule. However, explanations of altruism have typically not considered the stochasticity of natural environments, which will not necessarily favour genotypes that produce the greatest average reproductive success. Moreover, empirical data across many taxa reveal associations between altruism and environmental stochasticity, a pattern not predicted by standard interpretations of Hamilton's rule. Here we derive Hamilton's rule with explicit stochasticity, leading to new predictions about the evolution of altruism. We show that altruists can increase the long-term success of their genotype by reducing the temporal variability in the number of offspring produced by their relatives. Consequently, costly altruism can evolve even if it has a net negative effect on the average reproductive success of related recipients. The selective pressure on volatility-suppressing altruism is proportional to the coefficient of variation in population fitness, and is therefore diminished by its own success. Our results formalize the hitherto elusive link between bet-hedging and altruism, and reveal missing fitness effects in the evolution of animal societies.