I read your story carefully and I want to say - you were there with Fred when he died. Maybe not in the physical, but in the spiritual. It sounds to me like he slipped away while he was laying next to you, as you were petting him. Just because his heart kept beating for a while, doesn't mean he was still there. I think his spirit left as you were there with him.
As someone else said earlier, if you would'nt have taken him to the vet, that would have been failing him. You were actually quite heroic in your actions that day.
Please don't feel guilty. So many dogs live tragic lives with no one to love them. Fred had a wonderful life because of YOU.
P.S. Give God a chance.