The increasing carbon emission of polluted rivers in urban areas is an environmental problem commonly faced by many cities in China, especially the megacities with vast populations. In this study, two typical rivers located in the megacity of Shanghai, including the suburban river network R1 and urban river R2 (in the central city), were investigated for their emission characteristics of CO2 and CH4 in dry and wet weather. We also analyzed the relationship between the state and type of river pollution and CO2 and CH4 emissions, and further explained the mechanisms of CO2 and CH4 emissions in urban rivers impacted by sewage discharged from the municipal drainage network. The results show that:① In dry weather, the average fluxes of CO2 and CH4 emitted from the river in the central city (R2) were (2.48±1.02) mmol·(m2·h)-1 and (1.21×10-2±0.71×10-2) mmol·(m2·h)-1, respectively. The average fluxes of CO2 and CH4 from the suburban river (R1) network were (1.53±0.39) mmol·(m2·h)-1 and (9.26×10-3±9.18×10-3) mmol·(m2·h)-1, respectively. In wet weather, affected by sewage from the municipal drainage network, CH4 flux emitted from the surface water of the R2 river downstream of the pump station P increased by up to 119 times that in dry weather. ② Global carbon emission statistics, involving the data from our study and from other rivers around the world, seemed to imply a relationship between the carbon emission flux and the pollution state of an urban river, i.e., the rivers with high pollution showed significant carbon emission intensity. ③ According to the results of PCA, organic matter can be an essential factor in driving the variation of carbon emissions, and this trend is evident in all the rivers in urban and suburban areas. The relationship between carbon emissions and nitrogen pollution in a river varies with different types of underlying riparian surface. In the less polluted urban rivers, the aquatic physical factor can also be an essential factor. ④ In the short term, with massive quantities of sewage discharged into urban rivers, a large amount of CH4 flux can be emitted. In contrast, in the long run, the carbon cycle can be strengthened when the carbon storage is increased, and thus the emission potential of CO2 and CH4 is improved.