The magnesium transporter 1 (MAGT1) is a critical regulator of basal intracellular free magnesium (Mg(2+)) concentrations. Individuals with genetic deficiencies in MAGT1 have high levels of Epstein-Barr virus (EBV) and a predisposition to lymphoma. We show that decreased intracellular free Mg(2+) causes defective expression of the natural killer activating receptor NKG2D in natural killer (NK) and CD8(+) T cells and impairs cytolytic responses against EBV. Notably, magnesium supplementation in MAGT1-deficient patients restores intracellular free Mg(2+) and NKG2D while concurrently reducing EBV-infected cells in vivo, demonstrating a link between NKG2D cytolytic activity and EBV antiviral immunity in humans. Moreover, these findings reveal a specific molecular function of free basal intracellular Mg(2+) in eukaryotic cells.