Solar sunspots were known to chinese astronomers and there are very ancien records. We also know from radioactive dating in trees and ice that the solar cycle has been there for many millions of years.
In 1919, an Irishman, Joseph Larmor, proposed that these spots were magnetic in origin, and that the magnetic field of the Sun was itself generated by the internal fluid movements in the Sun. Just like moving electrons in a wire generate a magnetic fields, moving plasma or fluids conducting of electricity (like the liquid iron bit of the Earth core, which also makes its own magnetic field) generate magnetic field through what we call electromotive forces.
He was right. However, in the early 1930s, an English astronomer, Thomas Cowling, first showed, using some symmetry principles applied to the equations of fluid motions and Maxwell's equations, that simple fluid motions with too much symmetry (like, flows not depending on longitude) or too low-dimensional (like, flows in a meridional plane) could not generate magnetic fields. For geometric reasons, the problem is, in essence, fully three-dimensional.