Objectives: Pneumothorax is a frequent complication during mechanical ventilation. Electrical impedance tomography (EIT) is a noninvasive tool that allows real-time imaging of regional ventilation. The purpose of this study was to 1) identify characteristic changes in the EIT signals associated with pneumothoraces; 2) develop and fine-tune an algorithm for their automatic detection; and 3) prospectively evaluate this algorithm for its sensitivity and specificity in detecting pneumothoraces in real time. Design: Prospective controlled laboratory animal investigation. Setting: Experimental Pulmonology Laboratory of the University of Sao Paulo. Subjects: Thirty-nine anesthetized mechanically ventilated supine pigs (31.0 +/- 3.2 kg, mean +/- SD). Interventions. In a first group of 18 animals monitored by EIT, we either injected progressive amounts of air (from 20 to 500 mL) through chest tubes or applied large positive end-expiratory pressure (PEEP) increments to simulate extreme lung overdistension. This first data set was used to calibrate an EIT-based pneumothorax detection algorithm. Subsequently, we evaluated the real-time performance of the detection algorithm in 21 additional animals (with normal or preinjured lungs), submitted to multiple ventilatory interventions or traumatic punctures of the lung. Measurements and Main Results: Primary EIT relative images were acquired online (50 images/sec) and processed according to a few imaging-analysis routines running automatically and in parallel. Pneumothoraces as small as 20 mL could be detected with a sensitivity of 100% and specificity 95% and could be easily distinguished from parenchymal overdistension induced by PEEP or recruiting maneuvers, Their location was correctly identified in all cases, with a total delay of only three respiratory cycles. Conclusions. We created an EIT-based algorithm capable of detecting early signs of pneumothoraces in high-risk situations, which also identifies its location. It requires that the pneumothorax occurs or enlarges at least minimally during the monitoring period. Such detection was operator-free and in quasi real-time, opening opportunities for improving patient safety during mechanical ventilation.