One of the most difficult challenges in machine learning is the training process of artificial neural networks, which is mainly concerned with determining the best set of weights and biases. Gradient descent techniques are known as the most popular training algorithms. However, they are susceptible to local optima and slow convergence in training. Therefore, several stochastic optimization algorithms have been proposed in the literature to alleviate the shortcomings of gradient descent approaches. The butterfly optimization algorithm (BOA) is a recently proposed meta-heuristic approach. Its inspiration is based on the food foraging behavior of butterflies in the nature. Moreover, it has been shown that BOA is effective in undertaking a wide range of optimization problems and attaining the global optima solutions. In this paper, a new classification method based on the combination of artificial neural networks and BOA algorithm is proposed. To this end, BOA is applied as a new training strategy by optimizing the weights and biases of artificial neural networks. This leads to improving the convergence speed and also reducing the risk of falling into local optima. The proposed classification method is compared with other state-of-the-art methods based on two well-known data sets and different evaluation measures. The experimental results ascertain the superiority of the proposed method in comparison with the other methods.