Effects of alkali metals (KCl, NaCl) and alkaline earth metals (CaO, MgCl2) on the evolution of nitrogen-containing compounds and product distribution during pyrolysis of phenylalanine were studied in this study. TG-IR was used to monitor the change of nitrogen-containing gases (NH3, HCN, HNCO) with temperature and their final releasing amounts. Using M06-2X method and 6-31g(d) basis group, the pyrolysis reaction paths of phenylalanine were simulated, and the influence mechanism of AAEMs on the evolution process of nitrogen-containing compounds was explored from the molecular level. The results show that KCl promoted the release of HCN and HNCO and inhibited the release of NH3; however, NaCl inhibited the production of NH3 and HCN, promoting the production of HNCO. Both CaO and MgCl2 promoted the release of HCN and NH3 and inhibited the release of HNCO, while MgCl2 had a minor effect on HNCO. Theoretical simulations reveal that the main reason for affecting the total amount of three nitrogen-containing gases is the competitive effect of AAEMs on the formation paths of aromatic nitrogen compounds. KCl and CaO inhibited the formation paths of aromatic ni-trogen compounds, while NaCl and MgCl2 function conversely.