The game was first published in 1974 by Gary Gygax and Dave Arneson. Gygax and Arneson were avid players of wargaming, in which players control armies. DnD was the first role-playing game to allow a player to play a single character and go on an adventure. The roots of wargaming can still be seen today, as combat is often a focal point of DnD, much more so than other TTRPGs. The first editions of DnD were published as a basic ruleset, with a more advanced ruleset called Advanced Dungeons & Dragons, alongside it.
A period of misunderstanding and misinterpretation of DnD occured din the 80s in what is now called the Satanic Panic. Mostly Christian groups accused DnD of having satanic imagery and encouraging satanism and the occult. A famous comic written by a Christain evangelical named Jack Chick makes the claim that DnD leads to devil-worship and suicide. All of this is of course ridiculous, however the Satanic Panic did lead to a social stigma surrounding players of DnD which can still be seen today.
The Second Editions of DnD was published in 1989, and meant to tidy up the rules of AD&D. Due to the stigma following the Satanic Panic, all references to devils and demons, as well as otehr changes, were made to the game in 2e.
In the third edition, the various rules that had been spread accross several different source books were tidied together in one edition. The game was redesigned to make character creation easier and gameply smoother. En updated version, 3.5e, is still a popular version of the game today. 3e also saw the return of occult imagery to the game in spite of the still present stigma. 3e was also the first edition to use dice other than a d6.
The fourth edition of the game was published in 2008, and was met with a lot of backlash from the community. The rules, which hada been made easier to play in 3e, were redesigned yet again, but made incredibly complicated. Combat in 4e would tend to drag on for longer than it needed to due to the complexity of the game. In-game, the world of the Forgotten Realms also changed. In order to make the new rules for magic ucasting consistent, there was an in-universe even called the Spellplague, which massively changed almost every aspect of the Forgotten Realms canon.
The fifth edition, and by far the ost popular, was published in 2014. The game was developed with open play-testing from players, and was called DnD Next during development. New features continue to be developed with this play-testing model. 5e removed almost everything Wizards had changed in 4e, and made the game much easier to play and much easier to role-play in.
Due to this new ease of play, the game saw a huge boost in players. This boost, alongside the rise of online game streaming sites such as Twitch, led to popular groups airing their games live to viewers. The popularity of these streams in turn boosted the game's popularity further, and so on. DnD is now an incredibly popular game among all generations, with millions of players worldwide.