The aim of this study was to identify agronomic, ecological and sociocultural factors that could be modified to reduce the risk of aflatoxin contamination of peanuts from western Kenya. Presence of fungi within section Flavi of the genus Aspergillus and levels of total aflatoxin were determined for 436 peanut samples from the Busia and Homa bay districts. A total of 1458 cultures of Aspergillus flavus or A. parasiticus isolated from the samples were assayed for production of aflatoxin B1, B2, G1 and G2. Associations among the incidences of fungal species, incidences of samples with ≥10 μg kg−1 aflatoxin, production of specific aflatoxin types and various agronomic, ecological and sociocultural factors were modelled with chi-squared and logistic regression methods. The predominant species were A. flavus L-strain (78% incidence), A. flavus S-strain (68%) and A. niger (65%). Occurrence of A. caelatus, A. alliaceus and A. tamarii in Kenya was also documented. Samples from the Busia district were three times (odds ratio = 3·01) as likely to contain ≥10 μg kg−1 of total aflatoxin as were samples from the Homa bay district, while samples containing A. flavus S-strain were 96% more likely to exceed this threshold compared with samples from which this fungus was not isolated. Grading, planting improved cultivars and membership of a producer marketing group were negatively associated with the incidence of A. flavus, while crop rotation was negatively correlated with the incidence of B aflatoxins. These sociocultural factors can be modified to reduce the risk of peanut contamination with aflatoxin.