Magnesium (Mg2+) uptake systems are present in all domains of life given the vital role of this ion. Bacteria acquire Mg2+ via conserved Mg2+ channels and transporters. The transporters are required for growth when Mg2+ is limiting or during bacterial pathogenesis, but, despite their significance, there are currently no known structures for these transporters. Here we report the first structure of the Mg2+ transporter MgtA solved by single particle cryo-electron microscopy (cryo-EM). We obtained high resolution structures of both a homodimeric form (2.9 A), the first for a P-type ATPase, and a monomeric form (3.6 A). Each monomer unit of MgtA displays a structural architecture that is similar to other P-type ATPases with a transmembrane domain and two soluble domains. The dimer interface consists of contacts between residues in adjacent soluble nucleotide binding and phosphotransfer regions of the haloacid dehalogenase (HAD) domain. The ATP binding site and consequences of nucleotide binding were characterized by a combination of cryo-EM, molecular dynamics simulations, hydrogen-deuterium exchange mass spectrometry, and mutagenesis. Finally, our structure revealed a Mg2+ ion in the transmembrane segments, which, when combined with sequence conservation and mutagenesis studies, allowed us to propose a model for Mg2+ transport across the lipid bilayer. Our dimeric structures of MgtA also reveal regulatory features that have implications for related P-type ATPases such as the calcium pump SERCA.