Gygax acknowledged as much in the famed "Appendix N" to the original Dungeon Master's Guide, which listed his literary inspirations for the game. Geekier players know that the magic system in D&D comes from Jack Vance's Dying Earth stories, set in a far-future Earth where the study of magic (specifically, learn-fire-and-forget spells) has revived. Another entry on Gygax's list, the obscure and eccentric Margaret St. Clair novel Sign of the Labrys, seems to have provided the model for the archetypal "dungeon," an underground adventure site full of traps and with progressively more dangerous lower levels. St. Clair's novel took place in an underground shelter after an apocalyptic war here on Earth. I've written here of another seemingly-unlikely source, Sterling Lanier's Hiero's Journey, from which D&D appears to have taken some of its monsters (slime creatures and giant animals, in particular) and some of the inspiration for the cleric class. The designers' interest in psionic powers, which don't appear in either Tolkien or most pulp fantasy, also come from mid-century sci-fi, and may have specifically originated with Lanier's novel. And the archetypal D&D adventure often involves players exploring the ruins of an ancient culture, hunting for powerful magical items - a quest akin to Hiero's, or to the protagonist's in Andre Norton's Star Man's Son. (Appendix N doesn't mention this novel specifically but does list Norton as a source.)
The affect of Dungeons & Dragons also resembles that of a post-apocalyptic SF novel, rather than a fantasy epic. The rules encourage players to focus on their own survival and betterment; advancement is primarily based on resilience, combat skill, and acquiring treasure. The game's "alignment" system and the desire to prevent hurt feelings generally ensured players would behave ethically within their group, but otherwise enlightened self-interest was the highest rule. Critics who refer to stereotypical D&D characters as "murder hobos" weren't entirely wrong. A well-armed hobo wouldn't necessarily fit into an epic fantasy tale, but he'd fit right into a survivalist yarn. Maybe that's the best way to characterize Dungeons & Dragons, at least as most of its players have experienced it. Lord of the Rings is a fantasy inspired by, or at least strongly reminiscent of, World War Two, with its battle between good and evil and its happy ending. D&D is more about the aftermath of World War Three, where staying alive, getting stronger, and helping your friends is a far greater challenge, and endings are best postponed for a later session.
* Lord of the Rings has sold about 150 million copies since the 1950s; the movies have been seen by about 100 million people. Ewalt estimates that at least 200 million gamers have played either tabletop or computer fantasy role-playing games.