I agree with what others have stated and wanna add a couple of things.
-If practical issue a strong verbal command to the offender to drop his/her weapon prior to use.
-If possible immediately put your weapon back into concealment if the threat has been eliminated.
-Call 911 and tell them:
1. You were in fear for your life and shot someone
2. Where you are, and where the shooting took place
3. What you look like, what you are wearing, and that you are still armed
4. That you are hanging up to render first aid to others on scene
-Offer first aid and any other help you can to others on scene.
-When you observe the police entering the scene immediately put your hands up and inform them that you are armed and were scared for your life and shot someone trying to kill you/others.
-Follow the police's instructions EXACTLY.
-Reiterate to the police that you were in fear of losing your life and do not wish to make a statement at that time.
-Ask to speak to your attorney prior to making any statement.
-Expect the police to arrest you and take your weapon.
-Do not talk to anyone, even other family members about the events in question until after you have time to process everything and consult your attorney.
A couple of other tips/ideas:
One thing you can do is not look like a criminal. If your a military age male dress appropriately in clean, neat, and properly fitting clothing avoiding things that are loud or portray a strong belief or opinion, have a good clean haircut, keep your face/beard/etc neatly trimmed.
Get good training and learn to shoot and handle your weapon like a professional, use the same types of weapons that LEOs use nothing crazy looking so if you are observed by LE while defending yourself you look like a good guy. (This is especially true for long guns, if you keep an active shooter kit in your vehicle or whatever no AKs or tripped out foreign weapons, remember you wanna look like you belong on the good guy's side.)
Volunteer in your community and try to get to know the cops that patrol your area if possible, this would include things like volunteer Fire, EMTs, and Coast Guard Auxiliary etc.
NEVER turn toward the police with anything in your hand, just drop that shit and get on the ground.