The magnesium ion, Mg2+, 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 Ca2+ 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 Mg2+ influx is induced by antigen receptor stimulation in normal T cells and by growth factor stimulation in non-lymphoid cells. MAGT1 deficiency abrogates the Mg2+ influx, leading to impaired responses to antigen receptor engagement, including defective activation of phospholipase Cγ1 and a markedly impaired Ca2+ influx in T cells but not B cells. These observations reveal a role for Mg2+ as an intracellular second messenger coupling cell-surface receptor activation to intracellular effectors and identify MAGT1 as a possible target for novel therapeutics. The magnesium ion is the most abundant divalent cation in mammalian cells and is an essential cofactor for ATP, nucleic acids and numerous enzymes in animals and plants. Whether it serves as a second messenger in intracellular signalling — like calcium — has been controversial. New evidence suggests that it does. Li et al. identify mutations in the plasma membrane magnesium transporter MAGT1 in a novel X-linked immunodeficiency, and show that Mg2+ acts as a second messenger in responses triggered by T-cell receptors and EGF receptors. This identifies MAGT1 as a possible target for novel therapeutics.