Diabetes is a complex metabolic syndrome that is characterized by prolonged high blood glucose levels and frequently associated with life-threatening complications1,2. Epidemiological studies have suggested that diabetes is also linked to an increased risk of cancer3-5. High glucose levels may be a prevailing factor that contributes to the link between diabetes and cancer, but little is known about the molecular basis of this link and how the high glucose state may drive genetic and/or epigenetic alterations that result in a cancer phenotype. Here we show that hyperglycaemic conditions have an adverse effect on the DNA 5-hydroxymethylome. We identify the tumour suppressor TET2 as a substrate of the AMP-activated kinase (AMPK), which phosphorylates TET2 at serine 99, thereby stabilizing the tumour suppressor. Increased glucose levels impede AMPK-mediated phosphorylation at serine 99, which results in the destabilization of TET2 followed by dysregulation of both 5-hydroxymethylcytosine (5hmC) and the tumour suppressive function of TET2 in vitro and in vivo. Treatment with the anti-diabetic drug metformin protects AMPK-mediated phosphorylation of serine 99, thereby increasing TET2 stability and 5hmC levels. These findings define a novel 'phospho-switch' that regulates TET2 stability and a regulatory pathway that links glucose and AMPK to TET2 and 5hmC, which connects diabetes to cancer. Our data also unravel an epigenetic pathway by which metformin mediates tumour suppression. Thus, this study presents a new model for how a pernicious environment can directly reprogram the epigenome towards an oncogenic state, offering a potential strategy for cancer prevention and treatment.