Petrochemicals are one of the pillar industries of China. Despite this, the treatment of petrochemical wastewater has long been seen as a massive challenge in the field of water pollution control, hindering the high-quality and sustainable development of the petrochemical industry. The majority of petrochemical enterprises and zones are located near rivers or seas, so their wastewater discharges can easily cause watershed or regional water ecological risks. Specifically, nitrogen pollution in petrochemical wastewater poses a significant threat to water ecological safety and human health. Sludge samples were collected from a petrochemical wastewater A/O nitrogen removal process line in a chemical industry zone in Shanghai. Metagenomic and metatranscriptomic methods were used to analyze the community structure of microorganisms, the functional characteristics of nitrogen removal bacteria, and the key nitrogen metabolism pathways in different sludges during the period when effluent water quality was stable and fluctuating. During the study, it was found that the nitrite and nitrate removal was relatively stable in this process, but ammonia oxidation fluctuated easily. In the study of microbial communities, it was found to be a nitrification-denitrification pathway that primarily removed nitrogen from the A/O process, and no genes related to ANAMMOX were detected. Approximately 90% of the functional genes responsible for removing nitrogen were responsible for denitrification, whereas only 0.17% of them were involved in the conversion of ammonia nitrogen in the nitrification process. Moreover, the abundance of ammonia-oxidizing bacteria in the process was extremely low, and the main genus was Nitrosomonas . It is likely that this is the main cause of fluctuations in ammonia nitrogen concentration in effluent due to water quality shocks in the process line.