Neurons do something strange when starved of oxygen. First, they start firing randomly. Then they start to shut down. If they do not receive precious oh-two soon, they start to die.
This sequence is, of course, an oversimplification. You'll find counter examples all over the place.
Even so, this sequence explains a lot.
When certain parts of the brain (the temporal lobe and a few others) start misfiring, you receive a flood of memories. This can vary from an unusual montage of random events to full-blown hallucinations.
When the whole brain starts firing randomly, that's a seizure. But when parts of it spark off for no reason, it can create predictable effects. For example, in the occipital lobe, this can lead to seeing a spinning vortex of light. It's dark around the edges, probably because peripheral vision shuts down first.
Even your sense of balance can do weird things. The misfires followed by a shutdown can create the sense that every direction is the same.
And if the left brain weakens first (or the right brain starts misfiring more intensely), then you receive an incredible sense of peace, knowledge and connection to the universe. Even as your consciousness fades.
When conditions are right, you get a sense of floating, hallucinations, your life flashing before your eyes and the 'light-at-the-end-of-the-tunnel' effect.
And there you have it: a plausible, mundane explanation for near death experiences.
Is this model accurate?
I do not know.
It's probably missing a few details.
But, if it's in the right direction, it explains one of the most spiritual experiences people have without assuming that humans have souls. This works, even if we are no more than squishy meat computers.
Do not think I'm doing this because I'm a cruel, mirthless stereotype of a rationalist. The moral is not that, having explained it, the experience is meaningless.
No – the moral is that our brains are incredible.
If you want to experience any of those effects, you do not need to nearly die on a surgeon's table. The brain can create any of those experiences at any time.
Sure, it requires a lot of mind training to reach that point. And, yes, some are easier to achieve than others are.
But I've achieved most of them. I've had a few out-of-body experiences, most of them accidental. There were times when it felt like I floated around the room or down the street. I've talked to dead people (and fictitious people).
And I've felt the sublime joy that comes from being connected to the universe.
You do not need a soul, spirit, aura or any kind of disembodied energy shadow to do this. Your unconscious mind has incredible powers. As a child, you learn to suppress these experiences. It's a part of growing up and seeing what's real as opposed to what's “just” in your head.
Things in your head still have value, though. Every invention once exhausted as only a hallucination. Every metre of social progress was once a dream.
Your choice in life is not between embracing religion and living a dull, materialistic existence. There is magic in the mundane and sorcery in the science. Even bound by the laws of physics, the universe is amazing.
You are amazing.