We present a precise theoretical explanation and prediction of certain resonant peaks and dips in the electromagnetic transmission coefficient of periodically structured slabs in the presence of nonrobust guided slab modes. We also derive the leading asymptotic behavior of the related phenomenon of resonant enhancement near the guided mode. The theory applies to structures in which losses are negligible and to very general geometries of the unit cell. It is based on boundary-integral representations of the electromagnetic fields. These depend on the frequency and on the Bloch wave vector and provide a complex-analytic connection in these parameters between generalized scattering states and guided slab modes. The perturbation of three coincident zeros-those of the dispersion relation for slab modes, the reflection constant, and the transmission constant-is central to calculating transmission anomalies both for lossless dielectric materials and for perfect metals.