There are differing theories: one that explains it is that Donnie did die, and he was in a dream-like state so that he could cope with his death before finally meeting God. He could see that life is good and all, but if he had continued to live, then others would suffer and die.
Frank may be considered as an evil figure: he's tempting Donnie with the pleasures of life, but finally it occurs that his girlfriend dies, so he finally decides to go back in time.
The ending, he goes back in time and decides he should die, deciding if he lived too many people would suffer the consequences.
The beauty of the movie is how it's complicated and you can never fully decide on one thing.
