Mind flayer

Mind flayers and master mind flayers are especially perilous monsters, capable of eating your brain, resulting in feeling stupid, becoming forgetful, or perishing as your last thought fades away. Wearing a helmet, preferably greased, can sometimes protect you against the brain-eating attack. If you manage to eat one's corpse, you become smarter.

They can sense your presence remotely, and you theirs. If you have telepathy (such as from eating the corpse of a floating eye), then mind flayers can remotely attack you within a certain radius; they "lock on to your telepathy".

Strategy
Be careful not to run up to a mind flayer in melee thinking that it is a dwarf king; for some players, dwarves are easy kills while mind flayers are very dangerous. If you have felt the mind flayer's presence, that is your cue to check whether that is a dwarf. The message "You sense a faint wave of psychic energy" is your clue that there is a (master) mind flayer somewhere on the level, but you won't see it every turn.

Mind flayers as pets
Mind flayers make excellent pets, as they make quick work of shopkeepers, and their telepathic outreach is then soothing to you rather than harmful. However, in the late game, pet (master) mind flayers may wake up the Wizard of Yendor before you meant to fight him, causing you a host of problems. It is best to be very careful with such a pet in the later parts of Gehennom where the Wizard's Tower might be.

When fighting a mind flayer
Be cautious when fighting against a mind flayer.

Obtain a unicorn horn. There are many other good reasons to have a unicorn horn, but you can apply one to recover your lost intelligence; however it does not help against amnesia.

Avoid melee. Try to attack the mind flayer with ranged attacks. Those annoying master mind flayers can resist some magic attacks like force bolt, but you can still throw daggers or other weapons.

Wear a greased helmet. A helmet has a good but imperfect chance of preventing the mind flayer's tentacles from reaching you, especially if you flee as soon as possible. Greased helmets stay on longer than ungreased helmets under mind flayer attack.

Engrave or Burn Elbereth. Mind flayers respect Elbereth.

Special tactics
It is possible to stone a (master) mind flayer. If you have a source of cockatrice corpses or eggs, or you find a cockatrice located conveniently near a mind flayer, wear gloves, wield the corpse (or egg), and strike the mind flayer in melee. It only takes one hit (unless the mind flayer eats a lizard corpse).

Mind flayers can resist taming; the charm monster spell might or might not work. Be prepared to have the mind flayer attack you if your attempt of taming fails.

Many players find the amnesia attack so crippling that the genocide of all h becomes the best option. Be careful not to do this if you are a dwarf - dwarfs are also h, and this self-genocide has resulted in a lot of annoying deaths.

Source
Mind flayers appear in Dungeons & Dragons as Illithids. D&D's creator, Gary Gygax, was reportedly inspired to create the monster after seeing cover art for a book by Brian Lumley.