The notion of the gods needing worship - and their power being proportional to their worshippers' number (and quality) comes to D&D primarily through Leiber (Lean Times in Lankhmar and Under the Thumbs of the Gods) and Moorcock (where it's pretty ubiquitous), but the trope has a long history. Also in Fred Saberhagen, IIRC.
The Epic of Gilgamesh suggests that the gods would starve without their worshippers' sacrifices; Aristophanes in the Birds has a flock block the smoke rising to the gods and threaten to starve them - these are related ideas.
It crops up biblically - you defeat your neighbour, kill and enslave the population, steal the idol and other temple goods (usually to melt down) and disempower the god.
Much more recently, Pratchett and Gaiman.
I think it's a pretty persistent idea.