This paper investigated the effects of attapulgite addition on the physicochemical processes, heavy metal transformation, and microbial community during the composting of agricultural wastes and sediment. In addition, the correlation between environmental factors, heavy metals (HMs), and microbial community was also assessed by redundancy analysis (RDA). The results showed that pile B with attapulgite addition entered the thermophilic phase earlier and lasted longer than pile A as the control group. The reduction in the bioavailability of HMs (Cr, Cd, and Zn) was also greater in pile B, and the passivation of HMs was ranked as Cd > Zn > Cr. The relative abundance of phylum Proteobacteria, Firmicutes, Bacteroidetes, and Actinobacteria was the highest throughout the composting process. Furthermore, the RDA showed that the bacterial community composition was significantly correlated with temperature and C/N ratio in pile A, while significantly correlated with organic matter and pH in pile B. And the addition of attapulgite facilitated the conversion of HMs into more stable fractions by Pseudomonas. The study would provide a reference for the application of attapulgite to remediate the river sediment polluted by HMs.