Islanding detection is one of the conditions necessary for the safe operation of the microgrid. The detection technology should provide the ability to differentiate islanded operations from power grid disturbances effectively. Given that it is difficult to set the fault threshold using the passive detection method, and because the traditional active detection method affects the output power quality, a microgrid islanding detection method based on the Sliding Window Discrete Fourier Transform (SDFT)-Empirical Mode Decomposition (EMD) and Long Short-Term Memory (LSTM) network optimized by an attention mechanism is proposed. In this paper, the inverter output current and voltage at the point of common coupling (PCC) are transformed by the SDFT. The positive sequence, zero sequence, and negative sequence components of voltage and current harmonics are calculated and reconstructed by adopting the symmetrical component method (SCM). Meanwhile, the current and voltage are decomposed into a mono intrinsic mode function (IMF). The symmetric components of voltage, current, and IMFs are used as inputs to the deep learning algorithm. An LSTM with the features extracted to classify islanding and grid disturbance is proposed. By using the attention mechanism to set the weight values of the features of hidden states obtained by the LSTM network, the proportion of important features increases, which improves the classification effect. MATLAB/Simulink simulation results indicate that the proposed method can effectively classify the islanding state under different working conditions with an accuracy level of 98.4% and a loss value of 0.0725 with a maximal detection time of 66.94 ms. It can also reduce the non-detection zone (NDZ) and detection time and has a certain level of noise resistance. Meanwhile, the problem whereby the active method affects the microgrid power quality is avoided without disturbing the current or power of the microgrid.