Early-life nourishment exerts long-term influences upon adult physiology and disease risk. These lasting effects of diet are well established but the underlying mechanisms are only partially understood. Here we show that restricting dietary yeast during Drosophila development can, depending upon the subsequent adult environment, more than double median lifespan. Developmental diet acts via a long-term influence upon the adult production of toxic molecules, which we term autotoxins, that are shed into the environment and shorten the lifespan of both sexes. Autotoxins are synthesised by oenocytes and some of them correspond to alkene hydrocarbons that also act as pheromones. This study identifies a mechanism by which the developmental dietary history of an animal regulates its own longevity and that of its conspecific neighbours. It also has important implications for the design of lifespan experiments as autotoxins can influence the regulation of longevity by other factors including diet, sex, insulin signalling and population density.