The invention relates to the technical field of pear tree rot disease treatment, and discloses a method for preventing and treating rot disease by using endophyte. The method comprises the following steps: S1, preparing penicillium purpurogenum; S2, preparing sterile filtrate; S3, preparing a virus-carrying flat plate; S4, selecting pear tree branches; S5, punching holes in the branches by using a puncher, wherein the hole reaches the xylem; and S6, after treatment, placing the branches in an incubator to be subjected to moisture preservation treatment. According to the invention, a fungus JK2 is separated from a pear tree branch having rot disease, the fungus JK2 is identified as penicillium purpurogenum through morphology and molecular biology, a plate confrontation test shows that the fungus JK2 has strong inhibitory activity on pear tree rot fungi, the inhibition rate reaches 95% or above, an in-vitro pear tree branch identification result shows that the JK2 has a good prevention and treatment effect on the pear tree rot disease, and the penicillium purpurogenum is an endophytic fungus, is harmless to the environment and human bodies, and is beneficial to development of biopesticides.