Background Type 2 diabetes shows evidence of underlying heterogeneity. No studies have assessed whether different causes for diabetes change the response to oral hypoglycaemic therapy. In a few cases, patients with diabetes caused by mutations in the hepatocyte nuclear factor 1a (HNF-1a) gene have been described as sensitive to the hypoglycaemic effects of sulphonylureas. We aimed to see whether the glycaemic response to the sulphonylurea gliclazide and the biguanide metformin differed in HNF-1a diabetes and type 2 diabetes, and to investigate the mechanism for differences in sulphonylurea sensitivity. Methods We did a randomised crossover trial of glicazide and metformin in 36 patients, either with diabetes caused by HNF-1a mutations or type 2 diabetes, who were matched for body-mass index and fasting plasma glucose. The primary outcome was reduction in fasting plasma glucose. Analysis was by intention to treat. We assessed possible mechanisms for sulphonylurea sensitivity through insulin sensitivity, insulin secretory response to glucose and tolbutamide, and tolbutamide clearance. Findings Patients with HNF-1a diabetes had a 5.2-fold greater response to gliclazide than to metformin (fasting plasma glucose reduction 4·7 vs 0·9 mmol/L, p=0·0007) and 3.9-fold greater response to gliclazide than those with type 2 diabetes (p=0·002). Patients with HNF-1a diabetes had a strong insulin secretory response to intravenous tolbutamide despite a small response to intravenous glucose, and were more insulin sensitive than those with type 2 diabetes. Sulphonylurea metabolism was similar in both patient groups. Interpretation The cause of hyperglycaemia changes the response to hypoglycaemic drugs; HNF-1a diabetes has marked sulphonylurea sensitivity. This pharmacogenetic effect is consistent with models of HNF-1a deficiency, which show that the ß-cell defect is upstream of the sulphonylurea receptor. Definition of the genetic basis of hyperglycaemia has implications for patient management.