If he didn't have a gun, maybe he would be driven over by the car. Possibly a few more people too. In Europe, where guns are less prevalent, cars are the favorite weapon used by terrorists.
Luckily, he had a gun, so he was able to save himself and who knows how many more people by shooting an attacker.
People in the US get killed at a higher rate than all European countries by vehicles.