Abstract Drying is threatening global river ecosystems due to climate change, altering community composition and function even upon flow resumption. This mesocosm study investigated the greenhouse gas emissions fluxes and underlying mechanisms from benthic habitats prone to 20–100 days of drying. Results show that CO2 and N2O emissions from biofilms did not increase when drying increased, due to the changes in functional communities and genes. Notable is the transformation of biofilm from carbon source to sink following prolonged drying (mean emission fluxes ranged from 804.78 to −305.55 mg m2 h2). This was mainly due to strong increases in the abundance of genes involved in the Calvin–Benson–Bassham cycle (2.82 × 10−5 to 7.12 × 10−5), and functional taxa such as gemmatimonadota and pseudomonadota. These findings reveal a potential mitigation effect of drying on greenhouse gas emissions from rivers and streams, which could be relevant in the face of climate change.