Cecropins are the most potent induced peptides to resist invading microorganisms. In the present study, two full length cDNA encoding cecropin2 (Px-cec2) and cecropin3 (Px-cec3) were obtained from P. xylostella by integrated analysis of genome and transcriptome data. qRT-PCR analysis revealed the high levels of transcripts of Px-cecs (Px-cec1, Px-cec2 and Px-cec3) in epidermis, fat body and hemocytes after 24, 30 and 36 h induction of Metarhizium anisopliae, respectively. Silencing of Spätzle and Dorsal separately caused the low expression of cecropins in the fat body, epidermis and hemocytes, and made the P.xylostella larvae more susceptible to M. anisopliae. Antimicrobial assays demonstrated that the purified recombinant cecropins, i.e., Px-cec1, Px-cec2 and Px-cec3, exerted a broad spectrum of antimicrobial activity against fungi, as well as Gram-positive and Gram-negative bacteria. Especially, Px-cecs showed higher activity against M. anisopliae than another selected fungi isolates. Scanning electron microscopy (SEM) and transmission electron microscopy (TEM) revealed that cecropins exerted the vital morphological alterations to the spores of M. anisopliae. Based on our results, cecropins played an imperative role in resisting infection of M. anisopliae, which will provide the foundation of biological control of insect pests by using cecorpins as a target in the future.