Mycotoxin contamination poses a significant problem in developing countries, particularly in northern Pakistan's fluctuating climate. This study aimed to assess aflatoxin contamination in medicinal and condiment plants in Upper Dir (dry-temperate) and Upper Swat (moist-temperate) districts. Plant samples were collected and screened for mycotoxins (Aflatoxin-B1 and Aflatoxin-B-2). Results showed high levels of AFB-1 (11,505.42 ± 188.82) as compared to AFB-2 (846 ± 241.56). The maximum contamination of AFB-1 in Coriandrum sativum (1154.5 ± 13.43ng to 3328 ± 9.9ng) followed by F. vulgare (883 ± 9.89ng to 2483 ± 8.4ng), T. ammi (815 ± 11.31ng to 2316 ± 7.1ng), and C. longa (935.5 ± 2.12ng to 2009 ± 4.2ng) while the minimum was reported in C. cyminum (671 ± 9.91ng to 1995 ± 5.7ng). Antifungal tests indicated potential resistance in certain plant species (C. cyminum) while A. flavus as the most toxins contributing species due to high resistance below 80% (54.2 ± 0.55 to 79.5 ± 2.02). HPLC analysis revealed hydroxyl benzoic acid (5136 amu) as the dominant average phytochemical followed by phloroglucinol (4144.31 amu) with individual contribution of 8542.08 amu and 12,181.5 amu from C. cyaminum. The comparison of average phytochemicals revealed the maximum concentration in C. cyminum (2885.95) followed by C. longa (1892.73). The findings revealed a statistically significant and robust negative correlation (y = - 2.7239 × + 5141.9; r = - 0.8136; p < 0.05) between average mycotoxins and phytochemical concentrations. Temperature positively correlated with aflatoxin levels (p < 0.01), while humidity had a weaker correlation. Elevation showed a negative correlation (p < 0.05), while geographical factors (latitude and longitude) had mixed correlations (p < 0.05). Specific regions exhibited increasing aflatoxin trends due to climatic and geographic factors.