Bandpass filters based on guided-mode resonance effects in waveguide-grating structures are obtained by use of a genetic algorithm search-and-optimization routine. Calculated examples show that narrow linewidths, high peaks, and low sideband transmittances can be achieved in thin-film diffractive devices with few layers. A filter with a linewidth of 0.2 nm at a central wavelength of 0.55 microm is demonstrated in a two-layer-two-grating structure. At 10.6-microm wavelength, a filter consisting of a single binary grating is obtained that has a linewidth of 12.7 nm and extended, low sideband transmittance. A three-layer device with a surface relief Si grating and two underlying homogeneous layers of SiO(2) and Si yields a high-efficiency filter centered at 1.55 microm with a linewidth of 0.1 nm.