Pyrolysis is an effective method to convert organic wastes, such as sludge, into solid fuels, adsorbents, and catalysts. Further, the functional group distribution of the obtained char affects its application performance in subsequent combustion, adsorption, and catalysis field. In this work, the pyrolysis behaviors of sludge at different temperatures were studied by reactive molecular dynamics simulations, and the interphase migration of nitrogen and the evolution mechanism of nitrogen-containing functional groups in char were analyzed. The pyrolysis simulation process included a heating stage (300−2600 K), an early constanttemperature pyrolysis stage (2600 K, 500 ps), and a later constant-temperature pyrolysis stage (2600 K, 2 ns) that removed the influence of gas and tar. In the heating stage, the sludge mainly underwent fragmentation reactions. The pyrrole in the solid phase migrated to the liquid phase and evolved into the amine group, and the gas product mainly consisted of NH 3 . In the early stage of constant-temperature pyrolysis, the main reactions were the polymerization reactions of gas and tar with generating char. During the polymerization process, imine, pyrrole, and pyridine were formed due to cyclization and dehydrogenation. In the later stage of constant-temperature pyrolysis, char underwent a secondary cracking reaction. However, the main nitrogen-containing gas species remained unchanged, although the concentration of HCN increased. In addition, the cyano group in the char was converted into HCN or cyclized into pyridine, and some pyridine further evolved into a nitrogen-containing seven-membered ring and graphite nitrogen.