At the core of the CRISPR-Cas9 genome-editing technology, the endonuclease Cas9 introduces site-specific breaks in DNA. However, precise mechanistic information to ameliorating Cas9 function is still missing. Here, multi-microsecond molecular dynamics, free-energy and multiscale simulations are combined with solution NMR and DNA cleavage experiments to resolve the catalytic mechanism of target DNA cleavage. We show that the conformation of an active HNH nuclease is tightly dependent on the catalytic Mg2+, unveiling its cardinal structural role. This activated Mg2+-bound HNH is consistently described through molecular simulations, solution NMR and DNA cleavage assays, revealing also that the protonation state of the catalytic H840 is strongly affected by active site mutations. Finally, ab-initio QM(DFT)/MM simulations and metadynamics establish the catalytic mechanism, showing that the catalysis is activated by H840 and completed by K866, rationalising DNA cleavage experiments. This information is critical to enhance the enzymatic function of CRISPR-Cas9 toward improved genome-editing.