Objective To assess the association of serum magnesium with infection in new-onset systemic lupus erythematosus (SLE) patients. Methods We conducted a single-center retrospective cohort study of new-onset SLE patients from 2012 to 2021. The hospitalized SLE patients were divided into infection and noninfection groups. Logistic regression analysis was conducted to examine the association of hypomagnesemia with infection. Results A total of 476 new-onset SLE patients were included, with 299 cases in the infection group and 177 cases in the noninfection group. The patients were mostly females (81.7%). The average age at diagnosis was 43.7 years. The median duration was 1.0 month. The prevalence of hypomagnesemia (<0.70), normomagnesemia (0.70–1.10), and hypermagnesemia (>1.10) in new-onset SLE patients was 14.3%, 83.4%, and 2.3%, respectively. The prevalence of hypomagnesemia was 18.4% in the infection group and 7.3% in the noninfection group ( p = .001). The baseline value of serum magnesium was 0.819 mmol/L, with values of 0.799 mmol/L in the infection group and 0.854 mmol/L in the noninfection group ( p = .000). The following clinical variables were significantly different between the two groups ( p < .05): age, duration, hospitalization stay, fever, serositis, and SLE Disease Activity Index 2000 (SLEDAI 2K). The laboratory parameters, including hemoglobin, white blood cell count, albumin level, erythrocyte sedimentation rate (ESR), C-reactive protein (CRP), procalcitonin, and complement C3 were also significantly different between the two groups ( p < .05). The mortality was 4.4% (21/476), with 20 cases occurring in the infection group. Logistic regression analysis showed that hypomagnesemia was associated with an increased risk of infection ( p = .001) and poor prognosis ( p = .015). Conclusion Hypermagnesemia was rare in new-onset SLE patients. Hypomagnesemia was common and was associated with an increased risk of infection in new-onset SLE patients.