Magnesium has important structural, catalytic and signaling roles in cells, yet few tools exist to image this metal ion in real time and at subcellular resolution. Here we report the first genetically encoded sensor for Mg2+, MagFRET-1. This sensor is based on the high-affinity Mg2+ binding domain of human centrin 3 (HsCen3), which undergoes a transition from a molten-globular apo form to a compactly-folded Mg2+-bound state. Fusion of Cerulean and Citrine fluorescent domains to the ends of HsCen3, yielded MagFRET-1, which combines a physiologically relevant Mg2+ affinity (Kd = 148 µM) with a 50% increase in emission ratio upon Mg2+ binding due to a change in FRET efficiency between Cerulean and Citrine. Mutations in the metal binding sites yielded MagFRET variants whose Mg2+ affinities were attenuated 2- to 100-fold relative to MagFRET-1, thus covering a broad range of Mg2+ concentrations. In situ experiments in HEK293 cells showed that MagFRET-1 can be targeted to the cytosol and the nucleus. Clear responses to changes in extracellular Mg2+ concentration were observed for MagFRET-1-expressing HEK293 cells when they were permeabilized with digitonin, whereas similar changes were not observed for intact cells. Although MagFRET-1 is also sensitive to Ca2+, this affinity is sufficiently attenuated (Kd of 10 µM) to make the sensor insensitive to known Ca2+ stimuli in HEK293 cells. While the potential and limitations of the MagFRET sensors for intracellular Mg2+ imaging need to be further established, we expect that these genetically encoded and ratiometric fluorescent Mg2+ sensors could prove very useful in understanding intracellular Mg2+ homeostasis and signaling.