Of course, it may have been something else, too.
Is it possible that the brain prepares us for a peaceful ending? Showing paradise or whatever we like as we breath one last time?
That said, it could also just be an implementation quirk. There’s some interesting work out there on what exactly happens in the brain during the moments surrounding death, and it relates in an interesting way to the neural correlates of consciousness.
Also related to the state of being conscious without attentional content.
Think of it this way: a bear just ripped/slashed/whatever your arm off... which is more useful: 'arrgggghhh!' or for the brain to pump out endorphins so that you at least concentrate and have a chance of fighting back or running/limping away or hiding? I doubt the brain differentiates between serious injury and dying, it's just wired at a certain point to try to minimize the pain. That would seem to be a very useful evolutionary purpose.
Personally, I am christian, and my faith is a huge source of relief when thinking about big questions and personal crisis.
Be aware that many painkillers at end of life are administered by infusion pump. These control the maximum rate and frequency over time, and changes to the parameters are under a PIN code. Many such pumps also log their activity. You will have to look for a way to bypass these safeties, and not make it apparent to an external observer you extracted more medication than allotted in a given time period. I won’t spell out how to do that, because US policy and case law over assisted suicide must be changed before I may safely do so.