We investigate the impact of the magnetic field generated by colliding nuclei on heavy quark-antiquark interactions and heavy quark dynamics in the quark-gluon plasma (QGP). By means of the hard-thermal-loop resummation technique combined with dimension-two gluon condensates, the static heavy quark potential and heavy quark momentum diffusion coefficient, which incorporate both perturbative and nonperturbative interactions between heavy quarks and the QGP medium, are computed beyond the lowest Landau level approximation. We find that the imaginary part of the heavy quark potential in the magnetic field exhibits significant anisotropy. Specifically, the absolute value of the imaginary part is larger when the quark-antiquark separation is aligned perpendicular to the magnetic field direction, compared to when it is aligned parallel to the magnetic field direction. The heavy quark momentum diffusion coefficient in the magnetized QGP medium also becomes anisotropic. As the temperature rises, the influence of higher Landau levels becomes increasingly significant, resulting in a decrease in the anisotropy ratio of the heavy quark momentum diffusion coefficient to values even below 1. At sufficiently high temperatures, this ratio ultimately approaches 1. The nonperturbative interactions are indispensable for understanding heavy quark dynamics in the low-temperature region. We also study the response of viscous quark matter to the magnetic field and explore its implications for heavy quark potential, thermal decay widths of quarkonium states, as well as heavy quark momentum diffusion coefficient. Published by the American Physical Society 2024