Galaxy classification has an important role in understanding the formation of galaxies and the evaluation of our universe. Most of the machine learning methods were used to improve galaxy image classification. However, these methods suffer from some limitations, such as getting stuck in local point and slow convergence. Therefore, an alternative method to enhance the performance of galaxy images classification and avoid the limitations of other methods is proposed. The proposed method for galaxy classification (called BSOMFOG) is based on an improvement in the brain storm optimization (BSO) through combining it with the moth flame optimization (MFO). In this modified version of BSO (called BSOMFO), the MFO algorithm works as a local search operator to enhance the exploitation ability of BSO. The performance of the BSOMFO algorithm is compared against other algorithms through two experiments. In the first one, a set of 15 global optimization problems is used to evaluate the ability of the BSOMFO algorithm to find the solution for these problems. Meanwhile, in the second experiment, the BSOMFO is included in the BSOMFOG framework to improve the classification of the galaxy images into three classes, namely, spiral, lenticular, and elliptical. BSOMFOG consists of three phases: the first phase is to extract the shape, color, and texture features from the galaxy images, while the second phase used the BSOMFO algorithm to select the relevant features from the extracted features. The last phase is to evaluate the selected features through classification using the k-nearest neighbor classifier. The experimental results show that the BSOMFO algorithm provides better results than the traditional BSO algorithm and other metaheuristic algorithms to solve the optimization problem. Moreover, it makes the proposed BSOMFOG framework improves the classification accuracy (∼97 % ) for galaxy images, and its general purpose makes it suitable for automatic classification of galaxies.