Chronic infection with hepatitis B virus, alcohol consumption, and cirrhosis of the liver are recognized risk factors for primary liver cancer. A few, but not all, studies have suggested that diabetes mellitus also increases risk for this cancer. We conducted a population-based cohort study to analyze the risk of developing primary liver cancer and biliary tract (gallbladder, extrahepatic bile ducts, and ampulla of Vater) cancers among patients with diabetes. A cohort of 153 852 patients with a hospital discharge diagnosis of diabetes in the period from 1965 through 1983 was identified by use of the Swedish In-patient Register. Follow-up for these patients extended from the date of cohort entry through December 31, 1989. Incident cases of cancer during follow-up were identified through the Swedish Cancer Registry. To minimize the impact of selection bias, we excluded from the analysis patients who were diagnosed with liver and biliary tract cancers during the first year of follow-up. Standardized incidence ratios (SIRs) and their 95% confidence intervals (CIs) were computed by use of nationwide rates of liver and biliary tract cancers, adjusted for age, sex, and calendar year, for comparison. During 1–24 years of follow-up, 819 incident cancers in the combined category of primary liver (n = 533) and biliary tract (n = 286) were identified in the cohort, yielding an overall SIR of 2.5 (95% CI = 2.3–2.6). The risk was higher in men (SIR = 3.2; 95% CI = 2.9–3.6) than in women (SIR = 2.0; 95% CI = 1.8–2.2). The incidence of primary liver cancer alone was increased fourfold (SIR = 4.1; 95% CI = 3.8–4.5); again, the risk was higher in men (SIR = 4.7; 95% CI = 4.2–5.2) than in women (SIR = 3.4; 95% CI = 2.9–3.9). Smaller increases in risk were seen for cancers of the gallbladder, the extrahepatic bile ducts, and the ampulla of Vater. After exclusion of diabetic patients with concomitant diseases that predispose to primary liver cancer, such as alcoholism, cirrhosis, and hepatitis, the persistence of an approximately threefold excess risk was observed. Our findings suggest that patients with diabetes are at increased risk of developing primary liver cancer and perhaps cancers of the biliary tract. The mechanisms involved in the association of diabetes and liver cancer remain to be clarified. Additional studies are needed to determine whether patients with insulin-dependent diabetes mellitus and those with non-insulin-dependent diabetes mellitus differ in their risk for primary liver cancer or whether the risk is affected by the type of diabetes treatment. [J Natl Cancer Inst 1996;88:1472-77]