Antimicrobial peptides/proteins (AMPs) constitute a critical component of gut immunity in animals, protecting the gut from pathogenic bacteria. However, the interactions between AMPs and gut microbiota remain elusive. In this study, we show that leukocyte-derived chemotaxin-2 (LECT2)-b, a recently discovered AMP, helps maintain gut homeostasis in grass carp (Ctenopharyngodon idella), one of the major farmed fish species globally, by directly regulating the gut microbiota. Knockdown of LECT2-b resulted in dysregulation of the gut microbiota. Specifically, LECT2-b deficiency led to the dominance of Proteobacteria, consisting of proinflammatory bacterial species, over Firmicutes, which includes anti-inflammatory bacteria. In addition, the opportunistic pathogenic bacteria genus Aeromonas became the dominant genus replacing the probiotic bacteria Lactobacillus and Bacillus. Further analysis revealed that this effect was due to the direct and selective inhibition of certain pathogenic bacterial species by LECT2-b. Moreover, LECT2-b knockdown promoted biofilm formation by gut microbiota, resulting in tissue damage and inflammation. Importantly, LECT2-b treatment alleviated the negative effects induced by LECT2-b knockdown. These findings highlight the crucial role of LECT2-b in maintaining the gut microbiota homeostasis and mucosal health. Overall, our study provides important data for understanding the roles of AMPs in the regulation of gut homeostasis in animals.