The fungus Harpophora oryzae is a close relative of the pathogen Magnaporthe oryzae and a beneficial endosymbiont of wild rice. Here, we show that H. oryzae evolved from a pathogenic ancestor. The overall genomic structures of H. and M. oryzae were found to be similar. However, during interactions with rice, the expression of 11.7% of all genes showed opposing trends in the two fungi, suggesting differences in gene regulation. Moreover, infection patterns, triggering of host defense responses, signal transduction and nutritional preferences exhibited remarkable differentiation between the two fungi. In addition, the H. oryzae genome was found to contain thousands of loci of transposon-like elements, which led to the disruption of 929 genes. Our results indicate that the gain or loss of orphan genes, DNA duplications, gene family expansions and the frequent translocation of transposon-like elements have been important factors in the evolution of this endosymbiont from a pathogenic ancestor.