To provide a comprehensive insight into the enrichment mechanism of gallium and indium in No. 9 coals, eighteen samples were collected from Anjialing mine, Ningwu Coalfield, Shanxi Province for coal petrological, mineralogical and geochemical analyses. The results suggested that Ga and In enrichment mainly hosted in the top horizons, with average concentration coefficients of 8.99 and 2.73 respectively, compared with the rest of horizons (2.46 for Ga and 1.69 for In). Source apportionment indicated that Ga and In were mainly derived from bauxite of Benxi Formation in Yinshan Oldland, while In could originate from felsic magmatic rocks in Yinshan Oldland as well. In addition, weak oxidation condition, medium to intensive weathering, transgression and input of terrestrial higher plants had positive effects on Ga and In enrichment. With the rapid expansion of emerging electronics manufacturing, Ga and In, of which potential risks on human health were neglected previously, were recently considered as hazardous elements. Therefore, this paper also discussed the potential pathways that these elements threatened human health. We suggested that potential risks on environment and human health caused by Ga and In enrichment in coals and coal-related products should be taken into account besides their economic value.