A finite element modeling combined with the strain gradient theory (SGT) and the refined higher-order shear deformation beam theory is developed to study the dynamic instability of magnetically embedded functionally graded porous (FGP) nanobeams. Nanobeams with elastic foundation (EF) subjected to an axially oscillating load are analyzed. Nanobeams are made of functionally graded material (FGM) with an uneven porosity distribution. A three-node beam element with 8 degrees of freedom (DOFs) for two outer nodes and 2 DOFs for the middle node, which has the C1 and C2 continuous Hermite shape functions, is used to simulate nanobeams. Besides, Bolotin’s method is employed to determine the instability region of FGP nanobeams. The accuracy of the proposed method is tested by comparing it with other published works. In addition, the influences of various parameters such as magnetic potential, small-scale parameter, porosity coefficient, stiffness foundation, boundary conditions (BCs) on the dynamic instability of nanobeams are studied in detail.