Improving biological nitrogen fixation (BNF) in cereal crops is a long-sought objective; however, no successful modification of cereal crops showing increased BNF has been reported. Here, we described a novel approach in which rice plants were modified to increase the production of compounds that stimulated biofilm formation in soil diazotrophic bacteria, promoted bacterial colonization of plant tissues and improved BNF with increased grain yield at limiting soil nitrogen contents. We first used a chemical screening to identify plant-produced compounds that induced biofilm formation in nitrogen-fixing bacteria and demonstrated that apigenin and other flavones induced BNF. We then used CRISPR-based gene editing targeting apigenin breakdown in rice, increasing plant apigenin contents and apigenin root exudation. When grown at limiting soil nitrogen conditions, modified rice plants displayed increased grain yield. Biofilm production also modified the root microbiome structure, favouring the enrichment of diazotrophic bacteria recruitment. Our results support the manipulation of the flavone biosynthetic pathway as a feasible strategy for the induction of biological nitrogen fixation in cereals and a reduction in the use of inorganic nitrogen fertilizers.