Accurate prediction of spatial distribution of petroleum resources is important for petroleum exploration. Mahalanobis distance is a popular and effective method to predict the spatial distribution of oil and gas. However, this method has equal weights for each variable, exaggerates secondary variables, and is prone to misjudge when the distance is close or equal, which impairs the accuracy of classification. To solve these problems, this paper proposes a novel Mahalanobis distance method based on genetic algorithm (GA-MD) to optimize attribute weights. The Sangonghe Formation in the hinterland of the Junggar Basin was used as an example, the validity of GA-MD was evaluated in the exploratory well data set. Compared with the current mainstream methods, the results show that the accuracy of GA-MD method is the highest, and the accuracy is improved by 2–6.2%. The application effect of the proposed method is verified by the prediction result of oil and gas probability map, the GA-MD method not only shows higher oil and gas bearing probability in the reserve areas but also has better trend extrapolation ability compared with other methods. Based on the GA-MD results, the favorable zones with remaining petroleum resources in the Sangonghe Formation in the hinterland of the Junggar Basin were visualized. Three types of favorable oil and gas distribution areas are selected. The favorable areas provide a basis for quantitative decision-making for the optimization of the next drilling strategy and determination of oil and gas exploration deployment direction in the study area.