CD8 T cells, which have a crucial role in immunity to infection and cancer, are maintained in constant numbers, but on antigen stimulation undergo a developmental program characterized by distinct phases encompassing the expansion and then contraction of antigen-specific effector (T(E)) populations, followed by the persistence of long-lived memory (T(M)) cells. Although this predictable pattern of CD8 T-cell responses is well established, the underlying cellular mechanisms regulating the transition to T(M) cells remain undefined. Here we show that tumour necrosis factor (TNF) receptor-associated factor 6 (TRAF6), an adaptor protein in the TNF-receptor and interleukin-1R/Toll-like receptor superfamily, regulates CD8 T(M)-cell development after infection by modulating fatty acid metabolism. We show that mice with a T-cell-specific deletion of TRAF6 mount robust CD8 T(E)-cell responses, but have a profound defect in their ability to generate T(M) cells that is characterized by the disappearance of antigen-specific cells in the weeks after primary immunization. Microarray analyses revealed that TRAF6-deficient CD8 T cells exhibit altered expression of genes that regulate fatty acid metabolism. Consistent with this, activated CD8 T cells lacking TRAF6 display defective AMP-activated kinase activation and mitochondrial fatty acid oxidation (FAO) in response to growth factor withdrawal. Administration of the anti-diabetic drug metformin restored FAO and CD8 T(M)-cell generation in the absence of TRAF6. This treatment also increased CD8 T(M) cells in wild-type mice, and consequently was able to considerably improve the efficacy of an experimental anti-cancer vaccine.