It comes from real self-image where an individual believes himself to be the saviour of a group, time period, or in an extreme case, the world. Adolf Hitler suffered a Messiah complex.
There is however a time and a place for such mentalities, and regrettably, many consider them to either be preachy, delusional, insane, pretentious, or the may align them with any manner of negative perceptions. In some cases the negative perceptions can be warranted, but the world needs more people who believe they can change it for the better.
It would seem that a significant portion of people, at some point either fantasize about or take part in being/trying to be(come) a messiah of sorts, however such thoughts can be very constraining and the 'messiah' will often have the mentality to enact states or efforts of self-sacrifice in hopes that it makes a positive difference.