We developed a new method, based on alkaline diatomite solid-phase extraction followed by gas chromatography with mass spectrometry, for the simultaneous determination of the toxic contaminants ethyl carbamate (EC) and 4-(5-)methylimidazole (4-MEI) in yellow rice wine and soy sauce. The optimal extraction conditions were defined. With the application of alkaline diatomite solid-phase extraction, damage to the capillary column by organic acids was greatly reduced. With deuterated EC used as the internal standard, the linearity of the calibration curves for EC and 4-MEI was good with correlation coefficient above 0.99. In a spiked experiment with EC and 4-MEI in yellow rice wine and soy sauce, recovery of the added EC was 80.5-102.5% and that of 4-MEI was 78.3-92.8%. The limit of quantification and limit of detection for EC were 6.0 and 2.0 μg/kg, respectively, and for 4-MEI were 15.0 and 5.0 μg/kg, respectively. The validation results demonstrate that the method is fast, simple, and selective, and therefore is suitable for simultaneously determining the presence of EC and 4-MEI in fermented food.