Don't have a gun in your hand
Instinctively, individuals that carry firearms may immediately draw their weapon when they hear gunfire, even if they don't know where the gunshots are coming from. The only time you should draw your weapon is if you've clearly identified the shooter, and not another individual that may be armed. Remember that there may be other individuals or law enforcement officers who just arrived on scene and are not in uniform, and you may mistake them for the shooter. If you decide to engage the shooter after discharging your firearm, immediately holster it.
When law enforcement arrives on the scene, they are looking for anyone with a gun and may think you are the shooter. If you are unarmed and overpower the shooter and obtain their weapon, you should not hold them at gunpoint. Place the weapon, if it's a handgun, in a trashcan or some other type of container and put it in another room away from the shooter. If the shooter has a long gun, then wrap it in a jacket, blanket, or any other type of material.