Epidemiological studies have revealed a correlation between diabetes mellitus and elevated blood glucose levels with atrial fibrillation (AF). Blood glucose levels were assessed in critically ill atrial fibrillation patients to determine whether they correlate with 28-day mortality. This study incorporated a cohort of 13,105 critically ill patients diagnosed with AF from MIMIC-IV database. Both smooth curve analysis and cox proportional hazards regression were employed. The selected participants had a mean age of 73.7 ± 11.7 years, with an estimated 58.6% being male. Smooth curve regression showed that minimum glucose, maximum glucose followed non-linear curves with respect to 28-day all-cause mortality. The inflection points were 65 mg/dL and 166 mg/dL for minimum glucose and maximum glucose, respectively. There was a decreased risk of 28-day mortality observed with minimum glucose < 65 mg/dL (HR = 0.967, 95%CI 0.951 ~ 0.983, P < 0.001) and an increased mortality risk observed with it ≥ 65 mg/dL (HR = 1.007, 95%CI 1.005 ~ 1.009, P < 0.001). Increased maximum glucose contributed to lower risks of mortality when maximum glucose < 166 mg/dL (HR = 0.996, 95%CI 0.993 ~ 0.999, P = 0.012). However, there was no statistically significant correlation between an increase in glucose level and mortality (HR = 1.000, 95%CI 0.999 ~ 1.001, P = 0.511) among patients with a maximum glucose level of ≥ 166 mg/dL. These findings suggested that there exists a U-shaped association between minimum glucose levels and 28-day mortality in critically ill AF patients, as well as an L-shaped correlation between maximum glucose and mortality. However, additional research is necessary to explore the underlying factors contributing to this association.