Sometimes magnetic field can twist plasma in sun's atmosphere into helical shape which is called flux ropes. Magnetic field line loops around many times around itself to create this structure. This twisted shape magnetic field can store energy which can lust for months. But eventually the stored energy is released and the mass is flung out into space. Where the suns magnetic field becomes most twisted and reaches a certain stress limit it punctures the suns surface. At that place convection of sun's plasma is restrained. As a result sun's surface temperature decreases compared to other region. It can be cooled as much as 1000 degrees. The result is relatively dark spot is solar surface called sun spot. Sun spot are only dark compared to other bright material around it. If somehow we can isolate one sun spot in space it will shine 10 times brighter than full moon. These dark spots are actually plasma crater size of our entire earth.
Galileo discovered that dark spots are moving across in the face of the star. This was the first indication that sun is rotating. Not only the sun rotate but sun spot can also spin like hurricane in solar surface. And when they do their magnetic field line becomes extremely twisted. Twisted magnetic field lines mean more energy and more energy means the potential for huge eruption.