China has unquestionably led efforts to 'green' drylands, but an evaluation of the large-scale effects of afforestation in desert ecosystems mediated by soil microorganisms is lacking. The ecological functions of fungi are closely related to soil and plant health. Therefore, there is a lively interest in revealing the biogeographic patterns of root-associated (RAF) and soil fungal (SF) communities of Pinus sylvestris var. mongolica, a widespread evergreen tree endemic to Northern China. We revealed the community assembly of RAF and SF of natural forest and plantations in the Hulunbuir Desert, Horqin Desert, and Mu Us Desert and investigated fungal responses to geographical location, climate factors, soil properties, and stand age at regional and local scales. The results indicated that (1) SF was more diverse than RAF. For RAF, the diversity indices in the natural forest were significantly lower than those in plantations, and ectomycorrhizal fungi (50.37%) were the predominant functional guild in the natural forest. (2) At the local scale, SF, not RAF, is more sensitive to the impacts of soil properties. More than half of the differential genera were ectomycorrhizal and endophytic fungi, such as Acephala, Cadophora, Pustularia, and Trichoderma. (3) On the regional scale, precipitation and sunshine duration were the main influences on geographical differences in the fungal community composition. Geographical location directly and significantly influences RAF diversity and structure. The effect of climate factors on SF diversity was low, but it had a shaping effect on SF structure. Our results demonstrated that the fungal communities were geographically structured, a stable relationship was established between hosts and RAF, and soil nutrients had a significant impact on SF community composition. The ecological functions of fungi are important in evaluating afforestation efforts and maintaining stability in desert ecosystems.