The effects of external magnetic field on the steady-oscillatory transition of magnetohydrodynamic (MHD) natural convection in a three-dimensional cavity are investigated. The flow and heat transfer equations under subcritical condition are solved directly by the self-developed SCM-ACM with high accuracy, which has characteristics of exponential convergence, global approximation, numerical stability, and simplicity derived from the spectral collocation method (SCM) as well as the artificial compressibility method (ACM). The critical Grashof number (Grcr) under the magnetic fields of Ha = 0, 5, 10 and 20 are predicted by analyzing both the temporal velocity and amplitude signals in the subcritical condition, in conjunction with the Richardson extrapolation method. Then, the critical parameters for the steady-oscillatory transition of the magnetic field parallel to the X-, Y-, and Z-axes are considered. By analyzing the distribution of temperature amplitude and velocity amplitude, and comparing the Lorentz force and buoyancy force in different magnetic field directions, the effects of magnetic field directions on the stability for MHD natural convection are explained. The amplitude in the subcritical condition is exponentially decayed with time, and the decay rate of the amplitude exhibits a strict linear relationship with the Grashof number. The critical Grashof number of the first bifurcation of for Ha = 0, 5, 10, and 20 are (3.423, 3.431, 3.466, 3.733) × 106 accordingly. The periodic circulation is characterized by self-sustained oscillations around the main circulation surface (Z = 0.5). The amplitude is larger near the isothermal walls and the four corners. Since the Lorentz force generated by the magnetic field BZ is able to have an optimal stabilizing effect on the flow field in the main circulation surface, the steady state-oscillatory transition occurs at the higher Grashof number. At Ha = 5, the critical Grashof number of the magnetic fields Bx, By and BZ are (3.512, 3.431, 3.557) × 106.