The invention discloses automatic fire extinguishing method and system for an intelligent gun employing compressed air foam. The automatic fire extinguishing method comprises the following steps: firstly, detecting and positioning a fire source; once a fire occurs, immediately starting a fire source positioning procedure, and calculating the jet pitching angle of the intelligent gun, so as to automatically adjust the direction and angle of a gun muzzle; receiving a fire extinguishing instruction by a foam generating device, beginning to work, and turning on an electric control valve; and after the fire source is put out, enabling the foam generating device to stop working, and turning off the electric control valve. According to the automatic fire extinguishing method and system, automatic monitoring of the fire and fire extinguishing in an accurate positioning manner can be realized. The system is simple in structure, convenient to mount, large in protection range, timely in fire detection response, and high in fire extinguishing efficiency; the fire can be put out at an initial stage; the amount of a foam extinguishing agent and water is reduced; through controlling horizontal swinging of the intelligent gun around a fire source point as a center, the coverage range of the foam is greatly increased, the technical problem of extinguishing of large-area flowing fire caused by liquid fuel leakage is solved, and the reliability and the application range of the automatic fire extinguishing method for the intelligent gun employing the compressed air foam are improved.