Electrocardiogram (ECG) can visually reflect the physiological electrical activity of human heart, which is important in the field of arrhythmia detection and classification. To address the negative effect of label imbalance in ECG data on arrhythmia classification, this paper proposes a nested long short-term memory network (NLSTM) model for unbalanced ECG signal classification. The NLSTM is built to learn and memorize the temporal characteristics in complex signals, and the focal loss function is used to reduce the weights of easily identifiable samples. Then the residual attention mechanism is used to modify the assigned weights according to the importance of sample characteristic to solve the sample imbalance problem. Then the synthetic minority over-sampling technique is used to perform a simple manual oversampling process on the Massachusetts institute of technology and Beth Israel hospital arrhythmia (MIT-BIH-AR) database to further increase the classification accuracy of the model. Finally, the MIT-BIH arrhythmia database is applied to experimentally verify the above algorithms. The experimental results show that the proposed method can effectively solve the issues of imbalanced samples and unremarkable features in ECG signals, and the overall accuracy of the model reaches 98.34%. It also significantly improves the recognition and classification of minority samples and has provided a new feasible method for ECG-assisted diagnosis, which has practical application significance.