Despite increasing knowledge of barnyardgrass (Echinochloa crus-galli) interference with rice, relatively little is known how endophytes improve the ability of rice against barnyardgrass stress. Here, we provided a detailed temporal characterization of rice root-associated microbiomes during co-cultivation with barnyardgrass and a comparison with the microbiomes of weed-free rice plants. Alpha diversity analysis indicated that barnyardgrass had the opposite effects on endophytic bacteria and fungi in rice roots, in terms of the community diversity, richness and coverage at the rice seedling stage. Principal coordinate analysis showed that barnyardgrass had only a minor effect on the community composition of endophytes in rice roots at the rice seedling stage, but showed a significant and maximum interference at the heading stage. Rice recruited many endophytes to resist biotic stress from barnyardgrass, especially for fungi. PICRUSt (phylogenetic investigation of communities by reconstruction of unobserved states) predictive analysis indicated that 23 metabolic pathways of bacteria were overrepresented in rice. In addition, the main trophic mode of fungi was pathotroph according to FUNGuild analysis. A positive correlation between bacteria and fungi in rice roots was found via network analysis. Anaeromyxobacter, Azospira and Pseudolabrys were the vital bacteria, Phaeosphaeria and Funneliformis were the dominant fungi in maintaining the stability of the ecological network. These results provided data and a theoretical basis for the in-depth understanding of what role endophytes play in rice resistance to barnyardgrass stress and will have implications on improving the resistance of rice against biotic stress using root microbiota.