The global industrial revolution has led to a substantial rise in heavy metal levels in the environment, posing a serious threat to nature. Plants synthesize phenolic compounds under stressful conditions, which serve as protective agents against oxidative stress. Basilicum polystachyon (L.) Moench is an herbaceous plant of the Lamiaceae family. Some species within this family are recognized for their capacity to remediate sites contaminated with heavy metals. In this study, the effects of mercury (II) chloride and lead (II) nitrate on the in vitro propagation of B. polystachyon were investigated. Shoot tips from in vitro plantlets were cultured in Murashige and Skoog’s (MS) media with heavy metals ranging from 1 to 200 µM to induce abiotic stress and enhance the accumulation of phenolic compounds. After three weeks, MS medium with 1 µM of lead (II) supported the highest shoot multiplication, and the maximum number of roots per explant was found in 100 µM of lead (II), whereas a higher concentration of heavy metals inhibited shoot multiplication and root development. The plantlets were hardened in a greenhouse with a 96% field survival rate. Flame atomic absorption spectroscopy (FAAS) was used to detect heavy metal contents in plant biomass. At both 200 µM and 50 µM concentrations, the greatest accumulation of mercury (II) was observed in the roots (16.94 ± 0.44 µg/g) and shoots (17.71 ± 0.66 µg/g), respectively. Similarly, lead (II) showed the highest accumulation in roots (17.10 ± 0.54 µg/g) and shoots (7.78 ± 0.26 µg/g) at 200 µM and 50 µM exposures, respectively. Reverse-phase high-performance liquid chromatography (RP-HPLC) identified and quantified various phenolic compounds in B. polystachyon leaves, including gallic acid, caffeic acid, vanillic acid, p-coumaric acid, ellagic acid, rosmarinic acid, and trans-cinnamic acid. These compounds were found in different forms, such as free, esterified, and glycosylated. Mercury (II)-exposed plants exhibited elevated levels of vanillic acid (1959.1 ± 3.66 µg/g DW), ellagic acid (213.55 ± 2.11 µg/g DW), and rosmarinic acid (187.72 ± 1.22 µg/g DW). Conversely, lead (II)-exposed plants accumulated higher levels of caffeic acid (42.53±0.61 µg/g DW) and p-coumaric acid (8.04 ± 0.31 µg/g DW). Trans-cinnamic acid was the predominant phenolic compound in control plants, with a concentration of 207.74 ± 1.45 µg/g DW. These results suggest that sublethal doses of heavy metals can act as abiotic elicitors, enhancing the production of phenolic compounds in B. polystachyon. The present work has the potential to open up new commercial opportunities in the pharmaceutical industry.