Background: Nitrogen-fixing microorganisms (diazotrophs) provide biological available nitrogen and play a pivotal role in nitrogen cycling of mangrove sediments. However, most studies on diazotrophs have been restricted to easily accessible surface sediments, while the diversity, structure and ecological function of diazotrophic communities at the in-depth profile of mangrove sediments are largely unknown. Here, we investigated how biological nitrogen fixation vary with depth of mangrove sediments from the perspective of both NFR and diazotrophic communities.Results: Through acetylene reduction assay, nifH gene amplicon and metagenomic sequencing, we found that the nitrogen fixation rate (NFR) increased but the diversity of diazotrophic community decreased with the depth of mangrove sediments. The structure of diazotrophic communities at different depths was largely driven by salinity, and exhibited a clear divergence at the partition depth of 50 cm. Agrobacterium and Azotobacter were specifically enriched at 50-100 cm sediments, while aerobic diazotrophs such as Methylomonas had a higher abundance at 0-30 cm. Consistent with the higher NFR, metagenomic analysis indicated the elevated abundance of nitrogen fixation genes (nifH/D/K) in deeper sediment layers, where nitrification genes (amoA/B/C) and denitrification genes (nirK and norB) became less abundant. Three metagenome-assembled genomes (MAGs) of diazotrophs from deep mangrove sediments indicated their facultative anaerobic and amphitrophic lifestyles as they contained genes for low-oxygen-dependent metabolism, hydrogenotrophic respiration, carbon fixation and pyruvate fermentation.Conclusions: Together, this study determines the depth-related variability of NFR and diazotrophs, which potentially contribute to nitrogen sinks and relieve nitrogen limitation, especially in the deep sediments of mangrove ecosystems.