In the studies of the dynamic response of carbon nanotubes, the stability, predictable, and unpredictable chaotic vibrations are fundamental characteristics. In this paper, we investigate the chaotic and periodic vibrations of a single-walled carbon nanotube resting on the viscoelastic foundation, based on the nonlocal Euler–Bernoulli beam model. It is assumed that the single-walled carbon nanotube is subjected to an external harmonic excitation. The axial thermomagnetic field and the surface effect on the governing equation of single-walled carbon nanotube are taken into account. We also solve the nonlinear governing equation by using the Galerkin decomposition method along with the fourth-order Rung–Kutta numerical integration scheme. Furthermore, we analyze the effects of amplitude and frequency of excitation on the formation of chaotic and periodic regions using bifurcation diagrams and largest Lyapunov exponents. Moreover, we present the phase portrait, Poincare maps, and time history to observe the periodic and chaotic responses of the system. The results show that the nonlinear dynamic response of single-walled carbon nanotube is much more sensitive to both amplitude and frequency of excitation.