It wasn't your fault. You didn't know it was going to happen.
The search for sense in the seemingly senseless is one of the most instinctual coping skills a person can employ in the face of hardship. The idea that life and death is random creates a dissonance so sharp one simply can’t allow it to linger; so you search…and you sift…and you piece irreparably broken things back together, desperate for it all to make sense.
It’s common to ask questions after a loved one dies, because sometimes you want answers.
It may be hard for you to believe, because you now know how things turned out, but in the past you really didn’t know as much as you think you knew. You may have worried or had your suspicions, but you didn’t know. Or if you knew, the things you think you could have done differently weren’t quite as obvious to you then as they seem now. The reason I know this is because you are looking at things in hindsight, and hindsight is biased.
I'm sorry for your loss. Losing a friend is never easy.
I hope you can find a way to process this.