Demogorgon is the most difficult of the demon princes and, indeed, the most difficult monster of any sort to appear in NetHack. Fortunately, his appearance is not guaranteed and usually only occurs through demon summoning. He can be summoned directly by Orcus, Juiblex, or Yeenoghu, indirectly by any demon that can summon these (which must first summon one of those demon lords), or rarely by any spellcasting monster that casts "summon nasties" in Gehennom, which includes the Wizard of Yendor.
The safest approach to Demogorgon is not to meet him in the first place. As mentioned above, in vanilla NetHack, Demogorgon will not appear unless summoned, and Orcus, Juiblex and Yeenoghu are the most likely creatures to do this. Therefore, when facing any of these foes, kill them as expeditiously as possible. If you get bogged down fighting lesser threats, you are giving Demogorgon an opportunity to arrive every turn.
Conversely, if you want to meet Demogorgon, perhaps as the ultimate demonstration of your demon-hunting prowess, then take precautions against Orcus' wand of death and let him spend all the time he wants ineffectively zapping you with it. Demogorgon will be along eventually.
The only way to survive Demogorgon is to be prepared. Just as you carry an escape item for emergencies, work out your "Demogorgon Kit" and carry it in inventory when you enter Gehennom. Be very fast and unburdened, capable of curing diseases, and be able to both attack him and escape from him. A scroll of scare monster in a container is very helpful. Be aware that not even a blessed unicorn horn is perfectly reliable for curing sickness — the safest items are holy water, blessed potions of healing, extra healing, or full healing, or the cure sickness spell at 0% failure rate.
If Yeenoghu summoned him, you may have a hard time being neither confused nor stunned for a turn, and hitting to attack may be dangerous if it might move you onto some open space instead of hitting.
You should read the entry on his disease attack and understand the implications: his first attack will leave you with between 20 and (19 + constitution) turns to live, which is a fairly comfortable margin for healing yourself, but each subsequent disease attack he lands will reduce your remaining turns of life by roughly two-thirds. There is no way to know the exact value of your "turns to live" counter if you are diseased, so you should act as if the worst case were true in every circumstance.
As for how to actually kill him, there are several ways. First, you can beat him to death, but this is very slow and difficult to do. If you are not on the up stairs yourself, he will warp there to heal when you damage him, and if he needs to, he will use them to escape the level. He is not immune to stoning or disintegration, so you can kill him in that manner; if you have any wishes left, wishing for a cockatrice corpse could be a really good idea. Kate Nepveu, author of the Demogorgon FAQ reports killing Demogorgon by polymorphing into a cockatrice and allowing him to sting, but adds that this is a risky gambit and she "can't really recommend it." More reliable is polymorphing into a female cockatrice ahead of time, and laying a few eggs that you can use as petrification grenades. If you have a non-cursed scroll of earth and a ranged attack other than striking, you can keep him at a distance.
If you weren't planning to fight him, GET AWAY! Leave immediately and get past him. Teleport to the staircase, quaff a cursed potion of gain level, or zap a wand of digging downwards. Demogorgon will follow you to another level if standing next to you, even if you use a mechanism (such as cursed potion of gain level) that would not be available to him, so you must not be adjacent to him before attempting to escape to another level. You can do this by teleporting him, paralyzing him, being fast enough, damaging him so he teleports, etc. Use the breathing space to reassess, re-equip, and move back in on your own terms. Discretion is the better part of valor.
Staying on the upstairs
Most strategies for tackling Demogorgon involve getting to an upstairs before he can, since this is the only location Demogorgon will teleport to when he flees you to lick his wounds. If you are occupying this square, he has nowhere to teleport to, and he can't escape upstairs with you blocking the path. If you can reach the up-stairs first, you can beat on him for as long as you can hold out.
There are, of course, several ways of doing this. If you are not on a no-teleport level, you can teleport to the stairs. If you can escape one level up without Demogorgon pursuing you (see above), you can go to the downstairs of the higher level and simply walk down. If you can get to the downstairs on the current level and wait for Demogorgon to get next to you, you can walk down to the next level and let him pursue you. Or, perhaps you can paralyze Demogorgon (with a wielded or thrown potion of paralysis) and run there before he wakes up. If your plan involves walking down stairs, there is a risk that Demogorgon, and not you, will end up standing on the actual staircase square, so you must plan for this contingency (teleport him away, for instance, or damage him so he flees upstairs and try again). Above all, pay attention to the turn counter and get well if you are diseased!
You can also attempt to safeguard the upstairs so that Demogorgon will not attack you while on it. If you somehow manage to fight him outside of Gehennom, you can burn Elbereth to scare him off and prevent him from hitting or casting spells at you, but you won't actually be able to attack him as long as you stand on it. A scroll of scare monster will, in addition to this, let you attack him and will also work in Gehennom, making it the best option. However, take note that versions of NetHack after 3.6.1 may change this scroll to be less powerful than it is now.
If you are a Knight, are riding, and have a lance and expert skill in it, you may be able to joust Demogorgon to death before he gets a chance to teleport to the stairs (if you're lucky you'll even be able to hit him before he sickens you). If he does get away, you can just use a unicorn horn and try again.
In SLASH'EM, Demogorgon has his own lair somewhere between second and sixth level of Gehennom, as well as Juiblex, Yeenoghu and Orcus – so you will meet him, it's guaranteed. Note that Demogorgon's lair is a non-teleport level – don't even try to use your wand of teleportation. Demogorgon still can teleport to the staircase, and to you, as usual for a covetous monster.
Keep in mind, that the behavior of unicorn horns has changed in SLASH'EM, making them far less reliable. However Enchantment now matters a lot. You should come prepared with a highly enchanted horn to deal with the sickening attack.
In UnNetHack Demogorgon does NOT respect Elbereth. He sometimes appears in his own lair in Gehennom, but this is not guaranteed; the lair takes the form of a small self-contained maze surrounded by a moat of ice.
In Slash'EM Extended Demogorgon also does NOT respect Elbereth just like in UnNetHack, and is immune to stoning, so the usual strategy of throwing a cockatrice egg won't work either. He will always be waiting in his lair in the Gehennom; all chaotic major demons can randomly summon him on other dungeon levels, though.
Similar to the other variants, Demogorgon does not respect Elbereth, and has a guaranteed lair. This is found at the very bottom of Gehennom, typically only one or two levels before the vibrating square level.
He comes from Dungeons and Dragons. D&D in turn derived him from an invented pagan god, by Christian scholars. In both sources, he is a powerful demon.
According to D&D: He is 5.5 meters/18 feet tall and has a vaguely humanoid/reptilian body, with two mandrill (like baboons) heads, two long reptilian necks and two tentacles for arms.
His image graces the front cover of 4th edition D&D's Monster Manual 2.
A terrible deity, whose very name was capable of producing the
most horrible effects. He is first mentioned by the 4th-century
Christian writer, Lactantius, who in doing so broke with the
superstition that the very reference to Demogorgon by name
brought death and disaster.
[ Brewer's Concise Dictionary of Phrase and Fable ]
Demogorgon, the prince of demons, wallows in filth and can
spread a quickly fatal illness to his victims while rending
them. He is a mighty spellcaster, and he can drain the life
of mortals with a touch of his tail.