To examine the association between gallstones and cholecystectomy, we conducted a nationwide population-based cohort study in Denmark. Patients with a discharge diagnosis of gallstones from 1977 to 1989 were identified from the Danish National Registry of Patients and followed up for cancer occurrence until death or the end of 1993 by record linkage to the Danish Cancer Registry. Included in the cohort were 60 176 patients, with 471 450 person-years of follow-up. Cancer risks were estimated by standardized incidence ratios (SIRs) and 95% confidence intervals (CIs) stratified by years of follow-up and by cholecystectomy status. Among patients without cholecystectomy, the risks at 5 or more years of follow-up were significantly elevated for cancers of liver (SIR = 2.0, CI = 1.2-3.1) and gallbladder (SIR = 2.7, CI = 1.5-4.4) and near unity for cancers of extrahepatic bile duct (SIR = 1.1), ampulla of Vater (SIR = 1.0) and pancreas (SIR = 1.1). The excess risk of liver cancer was seen only among patients with a history of hepatic disease. Among cholecystectomy patients, the risks at 5 or more years of follow-up declined for cancers of liver (SIR = 1.1) and extrahepatic bile duct (SIR = 0.7), but were elevated for cancers of ampulla of Vater (SIR = 2.0, CI = 1.0-3.7) and pancreas (SIR = 1.3, CI = 1.1-1.6). These findings confirm that gallstone disease increases the risk of gallbladder cancer, whereas cholecystectomy appears to increase the risk of cancers of ampulla of Vater and pancreas. Further research is needed to clarify the carcinogenic risks associated with gallstones and cholecystectomy and to define the mechanisms involved.