Irrigation and fertilization practices can improve crop productivity in agroecosystems; however, the role of soil biodiversity in regulating crop production is not well understood. This restricts our ability to understand how changes in soil biodiversity impact soil function and crop productivity. To address this, a 4-year field experiment was conducted in China using three levels of irrigation [high (400 mm), medium (300 mm), and low (200 mm)] and two levels of fertilization [high (600 kg/ha P2O5 + 300 kg/ha urea) and low (300 kg/ha P2O5 + 150 kg/ha urea)] in arid farmland, to investigate maize production, soil properties, bacterial and fungal communities (diversity, compositions, N-cycling potentials, and co-occurrence networks), and their associations. The results showed that irrigation and fertilization had significant effects on bacterial and fungal community diversity, N-cycling potentials, and co-occurrence network patterns during maize growth. The combined treatment of medium irrigation and low fertilization resulted in higher maize yields, bacterial diversity, nitrification, ammoxidation, N-fixation potentials, and network modularity, compared with the other treatments. Strong and positive associations were observed between the soil N-cycling potentials, maize yields, and bacterial diversity; soils supporting a large number of bacterial taxa with co-occurrence network modularity had high soil nutrient levels (organic C and inorganic N) and maize yields. Structural equation modeling demonstrated that bacteria exhibited higher contribution to soil fertility and maize yields than fungi, and irrigation and fertilization indirectly affected microbial functions by altering bacterial diversity and network modularization, which also affected soil fertility and maize yields. These results highlight the importance of microbial diversity and their co-occurrence networks for maintaining soil fertility and crop production and will improve future irrigation and fertilization practices in arid agroecosystems and provide guidance for sustainable crop production.