Zuojin Pill (ZJP), a traditional Chinese medicine prescription composed of Rhizoma Coptidis and Euodiae Fructus in the ratio of 6:1 (w/w), has been widely used for the treatment of gastric disorders. However, an in-depth understanding of in vivo metabolism and distribution profiles of protoberberine alkaloids (PBAs) and indole alkaloids (IDAs) in ZJP is lacking. In this study, a method using ultra-high performance liquid chromatography coupled with quadruple time-of-flight mass spectrometry (UHPLC-Q-TOF-MS) was developed to systematically screen the alkaloids and their metabolites in rat plasma and various tissues after oral administration of ZJP. Furthermore, bioinformatics and molecular docking analyses were conducted to elucidate the contribution of the alkaloids and metabolites enriched in the stomach to the therapeutic effect of ZJP on gastritis. A total of 33 compounds, including 7 prototype alkaloids and 26 metabolites, were chemically defined or tentatively identified in this work. The metabolic pathways of PBAs (hydroxylation, oxidation, reduction, demethylation, demethylenation, glucuronide conjugation, sulfate conjugation) and IDAs (hydroxylation, glucuronide conjugation) were revealed. Notably, 7 prototype alkaloids and 18 metabolites were detected in the stomach, indicating their propensity for gastric distribution. These alkaloids and metabolites showed strong affinities with the 7 hub targets associated with gastritis, such as CCR7, CXCR4, IL6, IFNG, CCL2, TNF, and PTPRC, and could be considered the potential active substances of ZJP for treating gastritis. In conclusion, this study clarified the gastric distribution propensity of PBAs and IDAs and their metabolites, as well as their favorable binding interactions with gastritis-related targets, which could provide essential data for the further study of the pharmacodynamic material basis and gastroprotective mechanism of ZJP.