Background: Keystone genes exert great influence on maintaining microbiome stability and functional recovery irrespective of their environmental abundance. Elucidating the effects of environmental stresses on their variation is vital for identifying the recovery potential of ecosystems and regulating microbial adaptation within. Extracellular and intracellular gene transfer under pesticide-induced selection is convenient for studying keystone genes shifts and their role in ecosystem recovery potential. Results: Metagenomic analysis revealed that increased stress induced by organochlorine pesticides (OCPs) decreased soil bacterial diversity, and enriched abundance of functional genes associated with metabolism and gene transfer potential, both in extracellular and intracellular DNA. Increased OCP concentrations also significantly enhanced intercellular gene associations, which facilitated the abundance of keystone genes associated with metabolic functions by a factor of 2.14 times. Keystone genes devoted their niche specificity in microbiome co-occurrence networks, enhancing microbial survival under OCP stress where they had been taken up and incorporated by intercellular transfer. This was verified by culturing on media containing OCP (e.g., p-nitrochlorobenzene). Furthermore, in a 100-day field observation of ten different OCP-contaminated sites, China, keystone genes genes ssuD, livH, yfcG, coxA and gst, showed significant variations in abundance in response to the recovery of OCP-induced ecosystems and their intercellular transfer was promoted by 0~1.50 orders of magnitude. Conclusion: Under OCP-induced stress, the microbial community composition, community structure and certain transferable keystone genes all participate in the adaptive response to the environmental stresses. The observed gene transfers within the extracellular and intracellular DNA fractions emphasize the pivotal influence of keystone genes in maintaining ecosystem stability and resilience.