We monitored populations of two wood ant species, Formica aquilonia and Formica lugubris, through annual mapping of the colonies in a fragmenting forest landscape from 1966 to 1998. The genetic population structure was studied at the end of the study period by using 12 microsatellite loci. Fragmentation of forest led to a decline and spatial redistribution of populations. Changes in the spatial distribution were particularly pronounced in the highly polygynous (many queens in a single nest) species F. aquilonia, whose local populations declined or became extinct, or relocated themselves and colonized new patches. The genetic relationships of the remaining subpopulations indicated the historical developments, revealing the boundaries of the historical populations (high values of genetic differentiation, FST), recolonization histories (genetic affinities revealed by Bayesian analyses) and population decline (reduced variation). Big genetic differences could be detected over short distances, so differentiation also depended on social factors. Our results showed that a genetic study can be reliably used to dissect the recent historical changes underlying the present population structure, and that species with different social structures can respond differently to habitat changes. Combining our demographic and genetic results suggests that habitat fragmentation forms a clear threat on a local scale with large negative effects on ant population viability.