The magnesium ion, Mg(2+), is essential for all life as a cofactor for ATP, polyphosphates such as DNA and RNA, and metabolic enzymes, but whether it plays a part in intracellular signalling (as Ca(2+) does) is unknown. Here we identify mutations in the magnesium transporter gene, MAGT1, in a novel X-linked human immunodeficiency characterized by CD4 lymphopenia, severe chronic viral infections, and defective T-lymphocyte activation. We demonstrate that a rapid transient Mg(2+) influx is induced by antigen receptor stimulation in normal T cells and by growth factor stimulation in non-lymphoid cells. MAGT1 deficiency abrogates the Mg(2+) influx, leading to impaired responses to antigen receptor engagement, including defective activation of phospholipase Cγ1 and a markedly impaired Ca(2+) influx in T cells but not B cells. These observations reveal a role for Mg(2+) as an intracellular second messenger coupling cell-surface receptor activation to intracellular effectors and identify MAGT1 as a possible target for novel therapeutics.