Coal, as a typical fossil fuel, is a current major contributor to the global emission of nitrogen oxides (NOx). The NOx formation process during coal utilisation can be described as the thermal decomposition of N-containing model compounds into NOx precursors followed by NOx formation. The existence of alkali metal ions, Na+ and K+, during the coal utilisation process has a significant influence on the formation of NOx species. However, the information about this influence is currently lacking within the available literature. Within this research, the effect of Na+ and K+ on the formation mechanism of NOx during pyrrole pyrolysis were investigated using density functional theory (DFT). A hydrogen migration occurs from the meta-position of pyrrole-N is transferred to the ortho-position, and then pyrrole-N disconnected from the ortho-position C, which makes the ring opened. Lastly, in a concerted mechanism, a long carbon bond breaking between the migrating hydrogen and the carbon, nitrogen atoms. It was found that Na+ and K+ have a catalytic effect on the internal hydrogen transfer and ring-opening of pyrrole but have an inhibitory effect on internal hydrogen isomerization and concerted decomposition reaction. It was also found that those alkali metal ions (Na+ and K+) have strong interactions with pyrrole and its derived compounds (HCN and propyne molecules), those interactions are much larger than the existing attractive interactions among HCN, propyne molecules and their complexes. Additionally, it was found that both Na+ and K+ inhibit the HCN formation step from pyrrole pyrolysis, with Na+, has a higher inhibition effect than that of K+. Furthermore, the mechanisms discussed in this research may well play a role in the thermal decomposition of other coal compounds such as indole and carbazole.