Due to its fast learning speed, the extreme learning machine (ELM) plays a very important role in the real-time monitoring of electric power. However, the initial weights and thresholds of the ELM are randomly selected, therefore it is difficult to achieve an optimal network performance; in addition, there is a lack of distance selection when detecting faults using artificial intelligence algorithms. To solve the abovementioned problem, we present a fault diagnosis method for microgrids on the basis of the whale algorithm optimization–extreme learning machine (WOA-ELM). First, the wavelet packet decomposition is used to analyze the three-phase fault voltage, and the energy entropy of the wavelet packet is calculated to form the eigenvector as the data sample; then, we use the original ELM model coupled with the theory of distance selection to locate faults and compared it with the SVM method; finally, the whale algorithm is used to optimize the input weight and hidden layer neuron threshold of the ELM, i.e., the WOA-ELM model, which solves the problem of the random initialization of the input weight and hidden layer neuron threshold that easily affects the network performance, further improves the learning speed and generalization ability of the network, and is conducive to the overall optimization. The results show that 1) the accuracy of selecting the data according to the fault distance is twice that of not selecting data according to it; 2) compared with the BP neural network, RBF neural network, and ELM, the fault diagnosis model based on the WOA-ELM has a faster learning speed, stronger generalization ability, and higher recognition accuracy; and 3) after optimization of the WOA, the WOA-ELM can improve 22.5% accuracy in fault detection when compared to the traditional ELM method. Our results are of great significance in improving the security of smart grid.