Introduction: Due to the fact that the presence of high doses of aflatoxin in agricultural products such as cocoa beans is unacceptable in terms of national and international standards, appropriate quality control tests should prevent such products to entering in the process of processing cocoa beans. Conventional methods of detecting aflatoxins such as ELISA and HPLC are very time consuming, expensive and require expertise, so replacing these tests with non-destructive and rapid methods such as near-infrared spectroscopy can increase the detection efficiency. Brado et al. (Berardo et al., 2005) used infrared spectroscopy to evaluate and diagnose Fusarium verticillium, which produces fumonicin toxin in maize. Manvar et al. (Mohammadi Manvar, 2015) used transmission and reflection Infrared spectroscopy to detect aflatoxin levels in Iranian pistachios. Singh et al. (2012) used hyperspectral imaging in the range of 700-1100 nm to detect fungal contamination of Penicillium SPP, Aspergillus Glaucus, and Aspergillus Niger in wheat. Kandpal et al. (Kandpal et al., 2015) in a research work using hyperspectral imaging in the range of 700-1100nm classified grains of maize contaminated with aflatoxin toxin using PLS-DA into five groups. In current study, an attempt was made to detect the amount of aflatoxin in cocoa beans using infrared spectroscopy and to classify healthy and infected beans into groups.Materials and methods: In this research, 180 cocoa beans, each weighing 1 gram, were selected to do analyses. One mg of aflatoxin B1 powder (A. flavus, A 6636, Sigma-Aldrich, St. Louis, Mo USA) was prepared from Sigma Aldrich representative in Iran and by dissolving this powder in absolute ethanol and concentrations of 20µg/kg, 500µg/kg was obtained as mentioned. For cocoa bean spectroscopy, a near infrared spectrometer in Shiraz University Central Laboratory (NIRS XDS Rapid Content Analysis) was used, which has the ability to spectroscopy in the range of 400-2500 nm. PLS-DA method was used to classify aflatoxin-infected samples from healthy samples. All 180 experimental samples were divided into two groups of training (120 samples) and test (60 samples) and the constructed model was first calibrated with training values and then evaluated with test data. Due to the fact that some noise is always stored in the spectral data and in order to remove this noise, a series of mathematical pretreatment, including: first and second derivatives was used (Chen et al., 2013; Nicolai et al., 2007).Results & Discussion: Comparing the average amount of infrared reflection spectrum, it is revealed that healthy grains have less reflection intensity than infected grains. Also, there are a number of local maximums and minimums where the difference in reflective intensity is more pronounced than elsewhere, and this phenomenon is due to the different concentrations of toxins in cocoa beans. After applying the second Savitzie Golay derivative pretreatment and performing PLS-DA classification using two latent variables, the distinction between classes can be clearly seen. The separation rate of the samples on the second LV is more specific, however, the second and first class samples in this LV have a closer score to each other. The peaks observed at 1440 nm and 1482 nm according to the first Everton O-H bond can be related to fungal contamination (Berardo et al., 2005; C. D. Sirisomboon et al., 2013). Also, the peak at 1838 nm is related to the tensile C-H bond, which can be related to the CH2 groups. According to the results obtained from the calibration, cross-validation and testing sections, it is determined that the degree of calibration error (ER) and the degree of error-free calibration (NER) in the pretreatment mode with the second-order derivative of Savitz Golay are the lowest and highest values, respectively. Also, in this pretreatment for the calibration model and testing, the specificity index for the first, second and third class samples are equal to 1.00, which means that all classes are correctly classified. In the cross-validation model, the value of the specificity index for the third class (samples with 500 ppb contamination) is equal to 97%. This indicates that 97% of infected seeds are correctly classified in the third group and only 3% in the other groups are incorrectly classified.Conclusion: The present study demonstrates the feasibility of near-infrared spectroscopy to identify and classify cocoa beans contaminated with aflatoxin. The results showed that the coefficients of independent variables (spectral wavelengths including 1440, 1482 and 1838 nm) decreased according to increasing in the concentration of toxin. Finally, it can be said that the method of detecting aflatoxin contamination using infrared spectroscopy is an efficient, non-destructive and fast method.