Xylocoris flavipes (Reuter), the warehouse pirate bug, is a predator of many stored-products pests. This study compared the functional response of X. flavipes with different densities of the prey species Tribolium castaneum (Herbst), Oryzaephilus surinamensis (L.), Plodia interpunctella (Hübner), and Rhyzopertha dominica (F.) in two different habitats: empty glass jars and glass jars filled with wheat kernels that were designed to simulate more natural conditions in stored grain. Differences in the functional response of X. flavipes to all combinations of prey densities and grain conditions were compared with the predicted functional response curves from Holling’s type I and type II models, and to Hassell’s type III model. The functional response of X. flavipes was best described by Holling’s type II model, but a type III response occurred with prey that were more difficult to subdue, such as T. castaneum larvae. Numbers of prey attacked by females were greater than those attacked by males (P < 0.05) in both habitats for some of the prey life stages and species. The maximum attack rates for the different prey species in empty glass jars over 24 h were as follows: T. castaneum, 27.3 small larvae, 1.6 large larvae; O. surinamensis, 24.3 small larvae, 17.4 large larvae; P. interpunctella, 27.2 eggs, 23.7 small larvae; R. dominica, 26.4 eggs and 16.6 internally feeding larvae. The maximum number killed for the different prey species in glass jars containing wheat over 48 h were as follows: O. surinamensis 13.7 small larvae, 12.8 large larvae; P. interpunctella 41.4 eggs, 14.7 small larvae; R. dominica 22.0 eggs and 12.1 internally feeding larvae. Experiments with wheat-filled jars showed that single X. flavipes could locate and kill 27.1 out of 50 P. interpunctella eggs and 8.1 out of 10 R. dominica larvae inside kernels mixed into ≈18,000 kernels of wheat in 48 h.