As a chemotherapeutic drug, cyclophosphamide (CP) has a negative impact on male fertility due to its reproductive toxicity. Melatonin (Mel) promotes the male reproductive system and increases testosterone synthesis. This study is aimed at exploring the molecular mechanism of Mel as a protector of male fertility against CP-induced cytotoxicity. A CP toxicity model was established in adult ICR male mice by intraperitoneal injection of 100 mg/kg CP every other day for a week. Protective effects of Mel on the testis from CP-induced damage were evaluated using four groups of ICR male mice that received intraperitoneal injections of normal saline, 100 mg/kg CP, 10 mg/kg Mel, or the same dosage of CP and Mel, respectively. Testis morphology was observed by hematoxylin and eosin (HE) staining. Sperm quality parameters were evaluated, and sperm function was studied by in vitro fertilization (IVF). Proliferation, meiosis, and pyroptosis markers were examined by western blot. Results showed that CP treatment induced testis toxicity in a time-dependent manner with the most severe damage to the testis at two weeks post CP treatment. CP-treated mice showed reduced testicular weight and impaired spermatogenesis by downregulating PCNA and SYCP3, reduced serum testosterone levels, decreased sperm counts and motility, increased seminiferous tubule vacuolization, and oxidative damage to spermatogenic cells. All these effects, apart from testicular weight, could be ameliorated by Mel administration. The IVF experiment revealed that CP treatment reduced the rates of sperm fertilization and blastocyst development, which were also enhanced by Mel. Mel-treated mice also showed increased expression of proliferation-associated protein PCNA and meiosis-associated proteins REC8, STRA8, and SYCP3, which were all reduced by CP. Furthermore, Mel inhibited the pyroptosis of spermatogenic cells by reducing GSDMD and IL18 expression. In conclusion, this study indicated that Mel might protect the testis from CP-induced DNA damage to germ cells through the alleviation of pyroptosis.