Excess nitrogen in agricultural drainage poses a serious threat to the water quality safety of the Yellow River basin. Utilizing aquatic plants to modify the rhizosphere microbial community structure and facilitate nitrogen transformation is a crucial strategy for mitigating regional water eutrophication. Our results revealed that the denitrification rate (DR), dissimilatory nitrate reduction to ammonium rate (DNRAR) and nitrogen fixation rate (NFR) of rhizosphere sediments exhibited a significant increase in artificially cultivated ditch. Compared with those in natural ditches, the richness of the bacterial community and the relative abundances of Bacteroidota, Verrucomicrobiota, Firmicutes, Anaeromyxobacter and Geobacter, which are involved mainly in the nitrogen cycle, in the rhizosphere sediments of artificially cultivated ditch were significantly greater due to improvements in environmental conditions. In artificially cultivated ditch, the dominant functional genes affecting DRNARs in the rhizosphere sediments of P. australis were nrfC and nrfA, while DRs were driven mainly by norB and napA, which were influenced by the nitrogen and carbon levels; and the dominant functional genes affecting NFRs in the rhizosphere sediments of T. orientalis were nifD, nifK and nifH. Our results provide a scientific basis for the use of aquatic plants for mitigating excess nitrogen levels in agricultural drainage.