Objective - To compare well-being, performance, and longevity of gestating sows housed in stalls or in pens with an electronic sow feeder (ESF). Animals - 382 pregnant sows of parities 1 through 6. Procedure - Sows were housed in separate stalls (n = 176) or group pens (206) with an ESF. Well-being of sows was assessed at various time points in terms of injuries, salivary cortisol concentration, and behavior in a novel arena or to a novel object. Farrowing performance and longevity of sows were also assessed. Results - Total injury scores (TIS) of sows in pens were significantly higher at initial introduction and mixing. In stall-housed sows, TIS was significantly higher during late gestation. The TIS and cortisol concentration were significantly lower in stall-housed sows, compared with values for sows in pens. As parity increased, the likelihood of higher median TIS decreased significantly in pen-housed sows and increased significantly in stall-housed sows. The TIS of sows in pens was negatively correlated with body weight and backfat thickness, whereas these correlations were positive in stall-housed sows. Farrowing performance and results for novel arena or objects did not differ. Proportion of sows removed was significantly higher for pens than for stalls; lameness was the major reason for removal for both systems. Conclusions and clinical relevance - Stalls impose space restrictions for larger sows, resulting in injuries during late gestation. Interventions are needed to minimize aggression during initial introduction and mixing and at the ESF in pens to reduce severe injuries or lameness of gestating sows.