They're both correct and acceptable. I would perhaps read one very slight difference between the two:
1) ... the gun going off - this would suggest ongoing gunfire, perhaps from a machine gun or a pistol being fired several times
2) ... the gun go off - this suggests one single gunshot.