"brain releasing some form of chemical to make the passing from life into death easier"
I think this is closer to the truth, probably endorphin related, at a wild guess.
I personally think what happens is this. When someone dies, their bodily functions stop, one by one. The last one to go is the brain. If the brain is starved of external stimuli (taste, smell, touch, sight, sound), what happens is that you get an effect of "life flashing before your eyes". The latter has been observed by people who have gone into sensory deprivation tanks - they have the same effect (and even the "go to the light" effect). I would imagine the imagined presence of people who have previously died is part and parcel of the whole process.
One of the things that I was also told by a medic colleague was that people remain "conscious" or "aware" for a few minutes after death without being able to respond. So if you are with a loved one, it really does help to comfort them and tell them you love them. My sister did something like this with our late mum, and didn't know about the latter, and was reassured that she was able to make her peace with her (she had had a turbulent relationship with her).
i agree with the supposition that being dead is just like before we were born - no consciousness, nothing. Sad, but what I think as well. I think people struggle with this, and the mythos has grown around it to enable people to cope.