Diabetes mellitus (DM) has been associated with an increased risk of extrahepatic cholangiocarcinoma (ECC) and intrahepatic cholangiocarcinoma (ICC). However, the role of DM in a population with a lower incidence of ECC remains unclear. We investigated the role of DM and other risk factors for ECC and ICC by conducting a population-based, nested, case-control study in Taiwan, a region with a lower incidence but a higher proportion of ICC. We identified patients who received a diagnosis of cholangiocarcinoma (CC) from the Taiwan Cancer Registry between 2003 and 2009. A total of 6,093 CC cases (ICC: 4,695; ECC: 1,396) and 60,906 matched controls were included. Compared with the controls, the patients with ICC and ECC were more likely to have DM, with an adjusted OR of 1.22 [95% confidence interval (CI): 1.07-1.39] and 1.48 (95% CI: 1.18-1.85), respectively. DM was associated with an increased risk of CC in the women and patients without a history of biliary tract diseases. Moreover, compared with the controls, DM was not associated with an increased risk of ECC in the patients who received cholecystectomy. These findings strongly support the positive association between DM and the increased risk of both ICC and ECC; however, this association was not observed in the patients who received cholecystectomy.