Bacterial populations frequently act as a collective by secreting a wide range of compounds necessary for cell–cell communication, host colonization and virulence. How such behaviours avoid exploitation by spontaneous ‘cheater’ mutants that use but do not contribute to secretions remains unclear. We investigate this question using Pseudomonas aeruginosa swarming, a collective surface motility requiring massive secretions of rhamnolipid biosurfactants. We first show that swarming is immune to the evolution of rhlA-‘cheaters’. We then demonstrate that P. aeruginosa resists cheating through metabolic prudence: wild-type cells secrete biosurfactants only when the cost of their production and impact on individual fitness is low, therefore preventing non-secreting strains from gaining an evolutionary advantage. Metabolic prudence works because the carbon-rich biosurfactants are only produced when growth is limited by another growth limiting nutrient, the nitrogen source. By genetically manipulating a strain to produce the biosurfactants constitutively we show that swarming becomes cheatable: a non-producing strain rapidly outcompetes and replaces this obligate cooperator. We argue that metabolic prudence, which may first evolve as a direct response to cheating or simply to optimize growth, can explain the maintenance of massive secretions in many bacteria. More generally, prudent regulation is a mechanism to stabilize cooperation.