Aqueous two-phase systems (ATPSs) based on deep eutectic solvents (DESs) are green extraction and separation media and have demonstrated remarkable potential for extracting bioactive substances from natural matrices. However, thus far, flavonoid extraction using DES-based ATPSs has rarely been reported. In this study, the state-of-the-art technique using DES-based ATPSs was employed for developing an effective method for extracting flavonoids from Flos Sophorae Immaturus (FSI). DESs prepared with hexafluoroisopropanol (HFIP) and five quaternary ammonium salts, N111xCl (x = 1, 4, 8, 12, and 16), were used as the hydrogen bond donor and hydrogen bond acceptors, respectively, for constructing ATPSs with K2HPO4 as a salting-out agent and utilized for extracting flavonoids from FSI. Fourier-transform infrared, 1H nuclear magnetic resonance, 1H–1H nuclear Overhauser effect spectroscopy analyses, and density functional theory calculations were implemented to demonstrate the successful preparation of DESs. The DES containing dodecyltrimethylammonium chloride and HFIP with a molar ratio of 1:2 was screened as the optimal DES, showing a higher extraction efficiency and yield of flavonoids compared to those of other DESs and the traditional solvent ethanol. Subsequently, various experimental parameters (amount of DES, salt concentration, liquid-to-solid ratio, extraction temperature, and ultrasonic time) for the extraction process were studied comprehensively and optimized using response surface methodology. The yield of flavonoids from FSI was 21.05 % under optimal extraction conditions (amount of DES = 2 g, salt concentration = 0.21 g/mL, liquid-to-solid ratio = 81 mL/g, and extraction temperature = 60 ℃), which is close to the predicted value of 20.82 %. Extraction mechanisms underlying the performance of DES-based ATPSs during the extraction of bioactive substances are yet to be fully understood. Therefore, molecular dynamics (MD) simulations were employed with rutin as the target compound to probe the extraction mechanism under DES-based ATPS conditions, and the results revealed that hydrogen-bonded frameworks are pivotal for the extraction process. Moreover, the existence of K2HPO4 was found to promote not only the increase in hydrogen bonding networks and π–π stacking interactions within rutin molecules but also the increase in solvent flexibility, facilitating the extraction process. The present work offers a promising approach for flavonoid extraction using DES-based ATPSs. Interpreting the extraction mechanism at the molecular level by adopting the MD simulation technique provides new insights that enable a deeper understanding and aid in the design of the extraction process for bioactive substances under DES-based ATPS circumstances.