Background: Men who are overweight or obese frequently have low serum testosterone concentrations, which are associated with increased risk of type 2 diabetes. We aimed to determine whether testosterone treatment prevents progression to or reverses early type 2 diabetes, beyond the effects of a community-based lifestyle programme. Methods: T4DM was a randomised, double-blind, placebo-controlled, 2-year, phase 3b trial done at six Australian tertiary care centres. Men aged 50–74 years, with a waist circumference of 95 cm or higher, a serum testosterone concentration of 14·0 nmol/L or lower but without pathological hypogonadism, and impaired glucose tolerance (oral glucose tolerance test [OGTT] 2-h glucose 7·8–11·0 mmol/L) or newly diagnosed type 2 diabetes (provided OGTT 2-h glucose ≤15·0 mmol/L) were enrolled in a lifestyle programme and randomly assigned (1:1) to receive an intramuscular injection of testosterone undecanoate (1000 mg) or placebo at baseline, 6 weeks, and then every 3 months for 2 years. Randomisation was done centrally, including stratification by centre, age group, waist circumference, 2-h OGTT glucose, smoking, and first-degree family history of type 2 diabetes. The primary outcomes at 2 years were type 2 diabetes (2-h OGTT glucose ≥11·1 mmol/L) and mean change from baseline in 2-h OGTT glucose, assessed by intention to treat. For safety assessment, we did a masked monitoring of haematocrit and prostate-specific antigen, and analysed prespecified serious adverse events. This study is registered with the Australian New Zealand Clinical Trials Registry, ACTRN12612000287831. Findings: Between Feb 5, 2013, and Feb 27, 2017, of 19 022 men who were pre-screened, 1007 (5%) were randomly assigned to the placebo (n=503) and testosterone (n=504) groups. At 2 years, 2-h glucose of 11·1 mmol/L or higher on OGTT was reported in 87 (21%) of 413 participants with available data in the placebo group and 55 (12%) of 443 participants in the testosterone group (relative risk 0·59, 95% CI 0·43 to 0·80; p=0·0007). The mean change from baseline 2-h glucose was −0·95 mmol/L (SD 2·78) in the placebo group and −1·70 mmol/L (SD 2·47) in the testosterone group (mean difference −0·75 mmol/L, −1·10 to −0·40; p<0·0001). The treatment effect was independent of baseline serum testosterone. A safety trigger for haematocrit greater than 54% occurred in six (1%) of 484 participants in the placebo group and 106 (22%) of 491 participants in the testosterone group, and a trigger for an increase of 0·75 μg/mL or more in prostate-specific antigen occurred in 87 (19%) of 468 participants in the placebo group and 109 (23%) of 480 participants in the testosterone group. Prespecified serious adverse events occurred in 37 (7·4%, 95% CI 5·4 to 10·0) of 503 patients in the placebo group and 55 (10·9%, 8·5 to 13·9) of 504 patients in the testosterone group. There were two deaths in each group. Interpretation: Testosterone treatment for 2 years reduced the proportion of participants with type 2 diabetes beyond the effects of a lifestyle programme. Increases in haematocrit might be treatment limiting. Longer-term durability, safety, and cardiovascular effects of the intervention remain to be further investigated. Funding: Australian National Health and Medical Research Council, Bayer, Eli Lilly, University of Adelaide, and WW (formerly Weight Watchers).