Plants sustain intimate relationships with diverse microbes. While it is well recognized that these plant-associated microbiota shape individual performance and fitness of host plants, how they exert their function and maintain their homeostasis are largely unexplored. Here, using the pink lady plant (Heterotis rotundifolia) as a model, we investigated the phenomenon of microbiota-mediated nitrogen fixa-tion as well as the proximal homeostasis mechanisms of this process in the aerial root mucilage. The aerial root mucilage is enriched in primary metabolites such as carbohydrates, and abundant diazo-trophic bacteria. Nitrogen-labeled experiments and gene expression analysis indicate that the aerial root-mucilage microhabitat fixes atmospheric nitrogen to support plant growth. The presence of a key "police" fungus in the mucilage helps the host plant to defend against environmental microbes rather than diazotrophs. The discovery of new biological function and “police” fungi in the aerial root-mucilage microhabitat provides insights into microbial homeostasis maintenance of microenvironmental function and rhizosphere ecology.