Self affirmations is a kind of meditation, that is a specific state of mind, guided consciously. This kind of activity itself amends the person into a more direct and ordered state, actively improving the balance between the functioning of the sympathetic and parasympathetic systems.
This brings in the feeling of improvement and serves as a reward which helps to repeat self affirmation again. The more calm and ordered state of body lends even more control to the intellect which starts solving things, which also improves mood. This is widely used in medicine, for example, during child birth where the women are instructed to breathe calm and control the breath, which brings improvements of vital importance.
That being said, it is impossible to say, if self affirmation is primal. Maybe the fact itself of the sympathetic system function subsiding, gives birth to the feeling of improvement which is verbally perceived as a positive self affirmation. However, if free will is real then positive self affirmation is a good way to manifest it.
In any way the mechanism is complex and involves changing brain EM rhythms, probably with many other processes coming into play.