The magnesium ion Mg2+ is a vital element involved in numerous physiological processes. Mg2+ has the largest hydrated radius among all cations, whereas its ionic radius is the smallest. It remains obscure how Mg2+ transporters selectively recognize and dehydrate the large, fully hydrated Mg2+ cation for transport. Recently the crystal structures of the CorA Mg2+ transporter were reported. The MgtE family of Mg2+ transporters is ubiquitously distributed in all phylogenetic domains, and human homologues have been functionally characterized and suggested to be involved in magnesium homeostasis. However, the MgtE transporters have not been thoroughly characterized. Here we determine the crystal structures of the full-length Thermus thermophilus MgtE at 3.5 A resolution, and of the cytosolic domain in the presence and absence of Mg2+ at 2.3 A and 3.9 A resolutions, respectively. The transporter adopts a homodimeric architecture, consisting of the carboxy-terminal five transmembrane domains and the amino-terminal cytosolic domains, which are composed of the superhelical N domain and tandemly repeated cystathionine-beta-synthase domains. A solvent-accessible pore nearly traverses the transmembrane domains, with one potential Mg2+ bound to the conserved Asp 432 within the pore. The transmembrane (TM)5 helices from both subunits close the pore through interactions with the 'connecting helices', which connect the cystathionine-beta-synthase and transmembrane domains. Four putative Mg2+ ions are bound at the interface between the connecting helices and the other domains, and this may lock the closed conformation of the pore. A structural comparison of the two states of the cytosolic domains showed the Mg2+-dependent movement of the connecting helices, which might reorganize the transmembrane helices to open the pore. These findings suggest a homeostasis mechanism, in which Mg2+ bound between cytosolic domains regulates Mg2+ flux by sensing the intracellular Mg2+ concentration. Whether this presumed regulation controls gating of an ion channel or opening of a secondary active transporter remains to be determined.