In many stories, the gods' power is in some respects linked to the worship of their followers. The more followers a god has, the stronger (or at least the more able to influence the world, perhaps through those followers) that god is. It is common in such stories for Man to outgrow the need for gods, and so the gods, deprived of their worship, can no longer act in the world.
Petty gods might have an attitude of "well, fine then, if they won't worship me I'll take my ball and go home." But assuming truly benevolent gods who want the best for the world, if people—maybe because of increased reliance on technology, or in cynical response to all the times their gods didn't help them out—fall away from worshipping, those well-meaning gods might realize that their time of influence is coming to an end. In such a scenario, they would best serve their loyal following by teaching humanity how to get along without them, as they know their power is fading and soon they'll be unable to help even their most devout worshippers.
In the face of waning faith and reliance on the gods, benevolent gods would not want to cling to the last remnants of the faithful, dooming those followers to continue relying on them and worshipping them in vain. Those gods might instead help their followers learn how to be self-reliant, to ensure an orderly transition to life without the gods' guardianship. And, perhaps, the gods might then use their last powers to bestow powers or gifts upon their most devout adherents.
Those gods could then fade from the human sphere of influence knowing they'd left behind people who could make it on their own, and who would not remember the gods for having abandoned them, but would instead remember them fondly as the teachers and guides who led them beyond themselves and showed them how to stand on their own.