The aim of this study is to assess the impact of serum magnesium (Mg) levels on prognostic outcomes in patients with non-small cell lung cancer (NSCLC) undergoing treatment with epidermal growth factor receptor tyrosine kinase inhibitors (EGFR-TKI). A cohort comprising 91 patients with NSCLC with epidermal growth factor receptor mutations received EGFR-TKI therapy. Assessments of liver and kidney function and electrolyte levels were conducted before treatment initiation and after completing two cycles of EGFR-TKI therapy. Data on variables such as age, gender, presence of distant metastasis, smoking history, other therapeutic interventions, and the specific TKI used were collected for analysis. Cox regression analysis revealed that patients with higher Mg levels prior to EGFR-TKI therapy had significantly longer progression-free survival (PFS) and overall survival (OS). Elevated Mg levels remained predictive of PFS and OS after two cycles of EGFR-TKI therapy. Multiple regression analysis confirmed these findings. Additionally, it was observed that smokers might represent a unique population, demonstrating a correlation between OS and Mg levels. Our findings indicate that serum Mg level is a prognostic factor in patients with NSCLC undergoing EGFR-TKI therapy. This may provide new insights into the underlying mechanisms of EGFR-TKI therapy related to electrolyte balance.