The main aim of this study is to investigate the mechanism of the effect of the nitrogen-containing functional group of activated coke on SO2 adsorption through experiments and simulations. In this work, active coke with rich pyrrole and pyridine groups was prepared by ammonia modification. It has been found that the presence of pyrrole and pyridine groups, which can increase the surface polarity of active coke and the strength of non-covalent interactions, favors SO2 adsorption. Simulations show that the adsorption energy and non-covalent interaction strength of SO2, H2O and O2 on the surface and edge of active coke models with pyrrole group are greater than those with pyridine group, except for the adsorption of H2O on the edge of active coke. The presence of H2O reduces the adsorption capacity of SO2, mainly due to the competitive adsorption between H2O and SO2. Experimental research shows that the presence of H2O increases the content of S element on the active coke surface after adsorption. So, H2O not only promotes the adsorption of SO2, but also competes with it. Compared to O2, H2O forms stronger hydrogen bonds and dipole–dipole interactions with SO2, which can promote the adsorption of SO2.