BACKGROUND: Conventional treatments for patients with type 2 diabetes are often inadequate. We aimed to assess outcomes of diabetes control and treatment risks 2 years after adding Roux-en-Y gastric bypass to intensive lifestyle and medical management. METHODS: We report 2-year outcomes of a 5-year randomised trial (the Diabetes Surgery Study) at four teaching hospitals (three in the USA and one in Taiwan). At baseline, eligible participants had to have HbA1c of at least 8.0% (64 mmol/mol), BMI between 30.0 and 39.9 kg/m(2), and type 2 diabetes for at least 6 months, and be aged 30-67 years. We randomly assigned participants to receive either intensive lifestyle and medical management alone (lifestyle and medical management), or lifestyle and medical management plus standard Roux-en-Y gastric bypass surgery (gastric bypass). Staff from the clinical centres had access to data from individual patients, but were masked to other patients' data and aggregated data until the 2-year follow-up. Drugs for hyperglycaemia, hypertension, and dyslipidaemia were prescribed by protocol. The primary endpoint was achievement of the composite treatment goal of HbA1c less than 7.0% (53 mmol/mol), LDL cholesterol less than 2.59 mmol/L, and systolic blood pressure less than 130 mm Hg at 12 months; here we report the composite outcome and other pre-planned secondary outcomes at 24 months. Analyses were done on an intention-to-treat basis, with multiple imputations for missing data. This study is registered with ClinicalTrials.gov, number NCT00641251, and is still ongoing. FINDINGS: Between April 21, 2008, and Nov 21, 2011, we randomly assigned 120 eligible patients to either lifestyle and medical management alone (n=60) or with the addition of gastric bypass (n=60). One patient in the lifestyle and medical management group died (from pancreatic cancer), thus 119 were included in the primary analysis. Significantly more participants in the gastric bypass group achieved the composite triple endpoint at 24 months than in the lifestyle and medical management group (26 [43%] vs eight [14%]; odds ratio 5.1 [95% CI 2.0-12.6], p=0.0004), mainly through improved glycaemic control (HbA1c <7.0% [53 mmol/mol] in 45 [75%] vs 14 [24%]; treatment difference -1.9% (-2.5 to -1.4); p=0.0001). 46 clinically important adverse events occurred in the gastric bypass group and 25 in the lifestyle and medical management group (mainly infections in both groups [four in the lifestyle and medical management group, eight in the gastric bypass group]). With a negative binomial model adjusted for site, the event rate for the gastric bypass group was non-significantly higher than the lifestyle and medical management group by a factor of 1.67 (95% CI 0.98-2.87, p=0.06). Across both years of the study, the gastric bypass group had seven serious falls with five fractures, compared with three serious falls and one fracture in the lifestyle and medical management group. All fractures happened in women. Many more nutritional deficiencies occurred in the gastric bypass group (mainly deficiencies in iron, albumin, calcium, and vitamin D), despite protocol use of nutritional supplements. INTERPRETATION: The addition of gastric bypass to lifestyle and medical management in patients with type 2 diabetes improved diabetes control, but adverse events and nutritional deficiencies were more frequent. Larger and longer studies are needed to investigate whether the benefits and risk of gastric bypass for type 2 diabetes can be balanced. FUNDING: Covidien, National Institutes of Health, National Institute of Diabetes and Digestive and Kidney Diseases Nutrition Obesity Research Centers, and the National Center for Advancing Translational Sciences.