Background: The present study aimed to explore the relationship between serum anion gap (AG) and long-term mortality in patients undergoing coronary artery bypass grafting (CABG). Methods: Clinical variables were extracted among patients undergoing CABG from Medical Information Mart for Intensive Care III (MIMIC III) database. The primary outcome was four-year mortality following CABG. An optimal cut-off value of AG was determined by receiver operating characteristic (ROC) curve. The Kaplan-Meier (K-M) analysis and multivariate Cox hazard analysis were performed to investigate the prognostic value of AG in long-term mortality after CABG. In order to eliminate the bias between different groups, propensity score matching (PSM) was conducted to validate the findings. Results: The optimal cut-off value of AG was 17.00 mmol/L. Then a total of 3,162 eligible patients enrolled in this study were divided into a high AG group (≥17.00, n=1,022) and a low AG group (<17.00, n=2,140). A lower survival rate was identified in the high AG group based on K-M curve (p<0.001). Compared with patients in the low AG group, patients in the high AG group had an increased risk of long-term mortality [One-year: HR 2.309, 95% CI (1.672-3.187), P<0.001; two-year: HR 1.813, 95% CI (1.401-2.346), P<0.001; three-year: HR 1.667, 95% CI (1.341-2.097), P<0.001; four-year: HR 1.710, 95% CI (1.401-2.087), P<0.001] according to multivariate Cox hazard analysis. And further validation of above results were consistent in the matched cohort after PSM. Conclusions: The AG is an independent predictive factor for long-term all-cause mortality in patients following CABG, where a high AG value is associated with an increased mortality.