Quick grab me some ducktape a pair of needle nose plyers and a ball pump.. jk sorry friend you will have to take him to the vet they maybe able to correct or amputate if necessary but I'm sure he will be fine just try to make it as least stressful on him as you can. And avoid touching it as it may cause further discomfort/ stress.
I know it's upsetting but accidents happen so don't be to hard on yourself just look into how you can avoid this from happening again in the future. Were you in a rush and just not paying attention when closing it? Or the foliage maybe too dense near the entry making it always somewhat difficult to close due to debris or leaf matter being in the way? If so you should do some landscaping around the entry way or access panel. Either way my friend you should definitely have him evaluated by your vet. he could be in pain.