The adsorption of NH3 molecules on the pristine graphitic carbon nitride (gCN) and TM-embedded gCN systems (TM = Fe, Ru, and Os atoms) was investigated via periodic density functional theory calculations. The results indicated that the adsorption ability of NH3 molecules over the TM-embedded gCN systems remarkably enhanced, with respect to the pristine gCN with weak physisorption. According to the obtained results, it was shown that the interaction between NH3 molecule and the Os-embedded gCN, with high adsorption energy of − 2.73 eV, is much larger than those reported for the other reported adsorbents. Furthermore, it was found that the electrical conductivity of TM-embedded gCN systems after NH3 adsorption was considerably enhanced owing to the induced impurity states in the band gap energy. In addition, the results of magnetic calculations indicated that the NH3-adsorbed Os-embedded gCN displayed magnetic characteristics with magnetic moment of 0.08 µB, whereas the NH3-adsorbed Fe and Ru-embedded gCN systems are non-magnetic. Furthermore, the results of optimization showed that with adsorption of NH3 molecules on the pristine gCN, the initial planar structure of gCN automatically became buckles, because the wrinkle structure of gCN is more stable than the planar one. Finally, the results of Lowdin charges analysis illustrated that the electron transfer occurs from the TM-embedded gCN systems to NH3 molecules, thus this gas acts as an electron acceptor, whereas the embedded gCN systems serve as an electron donor. Based on the obtained results, it was found that the Os-embedded gCN system is more suitable candidate for sensing and removing of NH3 molecule than the other reported adsorbents.