The goal of this study is to optimize a UAE method for the extraction of the main bioactive compounds present in the ginger rhizome (gingerols and shogaols). Ginger rhizome (Zingiber officinale) has a considerable content of bioactive compounds, in particular gingerols and shogaols, with interesting pharmacological activities such as anti-inflammatory, antioxidant, anti-cancer, and antimicrobial properties, among others. The isolation of these compounds requires an efficient extraction process with short extraction times and the employment of specific non-toxic solvents for humans. In this work, the optimization of an ultrasound-assisted extraction (UAE) method for the extraction of the main pungent compounds in the ginger rhizome, i.e., gingerols and shogaols, has been carried out. For this purpose, a Box–Behnken design (BBD) has been used to optimize the experimental design through a response surface methodology (RSM). The percentage of ethanol in the extraction solvent, the temperature, the amplitude, and the cycle of the ultrasounds, as well as the sample-to-solvent ratio, were the variables to be studied. Thus, the percentage of ethanol in the extraction solvent was identified as the most influential factor. Once the compounds were extracted, the identification of gingerols and shogaols was performed by ultra-high-performance liquid chromatography (UHPLC) coupled to a quadrupole-time-of-flight mass spectrometer (Q-ToF-MS), and the quantification by UHPLC coupled to a diode array detector (DAD) detector. Finally, the optimized UAE method required only 10 min of extraction time, presenting good repeatability and intermediate precision levels (<5%). The method was applied to extract gingerols and shogaols from diverse sources, thereby demonstrating its applicability and highlighting the potential variations in compound concentrations across different samples based on factors such as origin, and growing conditions, among others.