The endophytic fungal communities of Polygonum acuminatum and Aeschynomene fluminensis were examined with respect to soil mercury (Hg) contamination. Plants were collected in places with and without Hg +2 for isolation and identification of their endophytic root fungi. We evaluated frequency of colonization, number of isolates and richness, indices of diversity and similarity, functional traits (hydrolytic enzymes, siderophores, indoleacetic acid, antibiosis and metal tolerance) and growth promotion of Aeschynomene fluminensis inoculated with endophytic fungi on soil with mercury. The frequency of colonization, structure and community function, as well as the abundant distribution of taxa of endophytic fungi were influenced by mercury contamination, with higher endophytic fungi in hosts in soil with mercury. The presence or absence of mercury in the soil changes the profile of the functional characteristics of the endophytic fungal community. On the other hand, tolerance of lineages to multiple metals is not associated with contamination. A. fluminensis depends on its endophytic fungi, since plants free of endophytic fungi grew less than expected due to mercury toxicity. In contrast plants containing certain endophytic fungi showed good growth in soil containing mercury, even exceeding growth of plants cultivated in soil without mercury. The data obtained confirm the hypothesis that soil contamination by mercury alters community structure of root endophytic fungi in terms of composition, abundance and species richness. The inoculation of A. fluminensis with certain strains of stress tolerant endophytic fungi contribute to colonization and establishment of the host and may be used in processes that aim to improve phytoremediation of soils with toxic concentrations of mercury.