Petroleum hydrocarbon pollution is a global problem. However, the effects of different petroleum pollution levels on soil microbial communities and ecological functions are still not clear. In this study, we analyzed the changes in microbial community structures and carbon and nitrogen transformation functions in oil-contaminated soils at different concentrations by chemical analysis, high-throughput sequencing techniques, cooccurrence networks, and KEGG database comparison functional gene annotation. The results showed that heavy petroleum concentrations (petroleum concentrations greater than 20,000 mg kg−1) significantly decreased soil microbial diversity (p = 0.01), soil microbiome network complexity, species coexistence patterns, and prokaryotic carbon and nitrogen fixation genes. In medium petroleum contamination (petroleum concentrations of between 4000 mg kg−1 and 20,000 mg kg−1), microbial diversity (p > 0.05) and carbon and nitrogen transformation genes showed no evident change but promoted species coexistence patterns. Heavy petroleum contamination increased the Proteobacteria phylum abundance by 3.91%–57.01%, while medium petroleum contamination increased the Actinobacteria phylum abundance by 1.69%–0.26%. The results suggested that petroleum concentrations played a significant role in shifting soil microbial community structures, ecological functions, and species diversities.