Well, almost the right thing. Yelling at the guy was not good. Fortunately, the guy was only nutty enough to wave a gun to scare you - not shoot at you. There is no gain in confronting a motorist.
The better move would have been to either turn down a side street, if available, turn around and go the other way, or just stop way behind the guy until he decides to move on. Few motorists will venture more than a few feet from their vehicle. Get the cell phone out and have it ready. Just showing the phone is likely to prevent a confrontation.