Magnesium ions (Mg2+) are vital for RNA structure and cellular functions. Present efforts in RNA structure determination and understanding of RNA functions are hampered by the inability to accurately locate Mg2+ ions in an RNA. Here we present a machine-learning method, originally developed for computer visual recognition, to predict Mg2+ binding sites in RNA molecules. By incorporating geometrical and electrostatic features of RNA, we capture the key ingredients of Mg2+-RNA interactions, and from deep learning, predict the Mg2+ density distribution. Five-fold cross-validation on a dataset of 177 selected Mg2+-containing structures and comparisons with different methods validate the approach. This new approach predicts Mg2+ binding sites with notably higher accuracy and efficiency. More importantly, saliency analysis for eight different Mg2+ binding motifs indicates that the model can reveal critical coordinating atoms for Mg2+ ions and ion-RNA inner/outer-sphere coordination. Furthermore, implementation of the model uncovers new Mg2+ binding motifs. This new approach may be combined with X-ray crystallography structure determination to pinpoint the metal ion binding sites.