Mg2+ is required for the catalytic activity of TrmD, a bacteria-specific methyltransferase that is made up of a protein topological knot-fold, to synthesize methylated m1G37-tRNA to support life. However, neither the location of Mg2+ in the structure of TrmD nor its role in the catalytic mechanism is known. Using molecular dynamics (MD) simulations, we identify a plausible Mg2+ binding pocket within the active site of the enzyme, wherein the ion is coordinated by two aspartates and a glutamate. In this position, Mg2+ additionally interacts with the carboxylate of a methyl donor cofactor S-adenosylmethionine (SAM). The computational results are validated by experimental mutation studies, which demonstrate the importance of the Mg2+-binding residues for the catalytic activity. The presence of Mg2+ in the binding pocket induces SAM to adopt a unique bent shape required for the methyl transfer activity and causes a structural reorganization of the active site. Quantum mechanical calculations show that the methyl transfer is energetically feasible only when Mg2+ is bound in the position revealed by the MD simulations, demonstrating that its function is to align the active site residues within the topological knot-fold in a geometry optimal for catalysis. The obtained insights provide the opportunity for developing a strategy of antibacterial drug discovery based on targeting of Mg2+-binding to TrmD