Background: Despite improvements in multidisciplinary management, patients with biliary tract cancer have a poor outcome. Only 20% of patients are eligible for surgical resection with curative intent, with 5-year overall survival of less than 10% for all patients. To our knowledge, no studies have described a benefit of adjuvant therapy. We aimed to determine whether adjuvant capecitabine improved overall survival compared with observation following surgery for biliary tract cancer. Methods: This randomised, controlled, multicentre, phase 3 study was done across 44 specialist hepatopancreatobiliary centres in the UK. Eligible patients were aged 18 years or older and had histologically confirmed cholangiocarcinoma or muscle-invasive gallbladder cancer who had undergone a macroscopically complete resection (which includes liver resection, pancreatic resection, or, less commonly, both) with curative intent, and an Eastern Cooperative Oncology Group performance status of less than 2. Patients who had not completely recovered from previous surgery or who had previous chemotherapy or radiotherapy for biliary tract cancer were also excluded. Patients were randomly assigned 1:1 to receive oral capecitabine (1250 mg/m 2 twice daily on days 1–14 of a 21-day cycle, for eight cycles) or observation commencing within 16 weeks of surgery. Treatment was not masked, and allocation concealment was achieved with a computerised minimisation algorithm that stratified patients by surgical centre, site of disease, resection status, and performance status. The primary outcome was overall survival. As prespecified, analyses were done by intention to treat and per protocol. This study is registered with EudraCT, number 2005-003318-13. Findings: Between March 15, 2006, and Dec 4, 2014, 447 patients were enrolled; 223 patients with biliary tract cancer resected with curative intent were randomly assigned to the capecitabine group and 224 to the observation group. The data cutoff for this analysis was March 6, 2017. The median follow-up for all patients was 60 months (IQR 37–60). In the intention-to-treat analysis, median overall survival was 51·1 months (95% CI 34·6–59·1) in the capecitabine group compared with 36·4 months (29·7–44·5) in the observation group (adjusted hazard ratio [HR] 0·81, 95% CI 0·63–1·04; p=0·097). In a protocol-specified sensitivity analysis, adjusting for minimisation factors and nodal status, grade, and gender, the overall survival HR was 0·71 (95% CI 0·55–0·92; p=0·010). In the prespecified per-protocol analysis (210 patients in the capecitabine group and 220 in the observation group), median overall survival was 53 months (95% CI 40 to not reached) in the capecitabine group and 36 months (30–44) in the observation group (adjusted HR 0·75, 95% CI 0·58–0·97; p=0·028). In the intention-to-treat analysis, median recurrence-free survival was 24·4 months (95% CI 18·6–35·9) in the capecitabine group and 17·5 months (12·0–23·8) in the observation group. In the per-protocol analysis, median recurrence-free survival was 25·9 months (95% CI 19·8–46·3) in the capecitabine group and 17·4 months (12·0–23·7) in the observation group. Adverse events were measured in the capecitabine group only, and of the 213 patients who received at least one cycle, 94 (44%) had at least one grade 3 toxicity, the most frequent of which were hand-foot syndrome in 43 (20%) patients, diarrhoea in 16 (8%) patients, and fatigue in 16 (8%) patients. One (<1%) patient had grade 4 cardiac ischaemia or infarction. Serious adverse events were observed in 47 (21%) of 223 patients in the capecitabine group and 22 (10%) of 224 patients in the observation group. No deaths were deemed to be treatment related. Interpretation: Although this study did not meet its primary endpoint of improving overall survival in the intention-to-treat population, the prespecified sensitivity and per-protocol analyses suggest that capecitabine can improve overall survival in patients with resected biliary tract cancer when used as adjuvant chemotherapy following surgery and could be considered as standard of care. Furthermore, the safety profile is manageable, supporting the use of capecitabine in this setting. Funding: Cancer Research UK and Roche.