Polar vortices are ubiquitous features of planetary atmospheric flows, from the Earth-like rocky planets to Jupiter- and Saturn-like gas giant planets. Very little is known about their existence or dynamics on the Sun. What should be expected near the Sun’s pole for the upcoming solar multi-viewpoint and polar missions? Here, we report the magnetohydrodynamic (MHD) nonlinear simulations for the formation and evolution of solar polar vortices using a near-surface MHD shallow-water model. Our findings indicate that the rush to the poles, the migration of magnetic fields toward the pole following the Sun’s magnetic cycle, can positively contribute to the formation of polar vortices. The mechanism proposed here for the formation of polar vortices involves the role of magnetic fields and may be relevant to any star with a magnetic cycle. The Sun’s polar vortices resulting from this mechanism are predominantly MHD, consisting of a tight pair of cyclonic and anticyclonic swirls. This mechanism is likely to operate during all solar cycle phases except the peak, when the polar field reverses. Polar vortices can impact dynamical evolution of global flows and polar fields, which seed the next activity cycle, hence better knowledge of physics of polar regions may lead to improved solar cycle and space weather forecasts.