Hypomagnesemia is significantly more frequent in acute pancreatitis (AP) patients. Magnesium sulfate is a routine drug used in clinical practice to treat hypomagnesemia. This study aimed to explore the association between magnesium sulfate administration and short-term mortality among intensive care unit (ICU)-admitted AP patients. Data of this retrospective cohort study were extracted from the Medical Information Mart for Intensive Care-III (MIMIC-III) and MIMIC-IV database. The exposure was magnesium sulfate administration during the ICU stay. The primary outcome was 30-day mortality. The secondary outcome was in-hospital mortality. The weighted univariate and multivariate cox proportional hazard models were utilized to explore the association between magnesium sulfate administration and 30-day mortality and in-hospital mortality among ICU-admitted AP patients, based on hazard ratios (HRs) and 95% confidence interval (CIs). Subgroup analyses were conducted based on different age, gender, scoring systems and complications. A total of 1,924 AP patients were included. Of these, 1,334 (69.33%) received magnesium sulfate administration. After adjustment for all covariates, magnesium sulfate administration was associated with a lower risk of 30-day mortality (HR=0.49, 95%CI: 0.36-0.66) and in-hospital mortality (HR=0.42, 95% CI: 0.31-0.57) among ICU-admitted AP patients. This association remained robust when subgroup analyses were conducted based on age, gender, history of hypomagnesemia, heart failure, hypertension, diabetes, liver disease, acute kidney injury and sepsis, and Bedside Index of Severity of Acute Pancreatitis (BISAP) and Charlson Comorbidity Index (CCI). The administration of magnesium sulfate may have potential benefits in improving the short-term prognosis of ICU-admitted AP patients.