Hydroxychavicol compound was isolated from Piper betle L. leaf and identified via preparative high performance liquid chromatography (Prep-HPLC) and nuclear magnetic resonance (NMR) spectroscopy. Hydroxychavicol compound was demonstrated to be a potential inhibitor for mild steel corrosion in carbon dioxide-containing environments due to the formation of a barrier layer on the steel surface. Scanning electron microscopy (SEM) and atomic force microscopy (AFM) results indicated that the inclusion of hydroxychavicol in the aggressive environment made steel surfaces more homogeneous and smoother with a rough mean square roughness of 7.78 nm, whereas the steel surface was severely corroded in the blank solution. Moreover, X-ray photoelectron spectroscopy (XPS) results showed an enrichment of hydroxychavicol species combined with iron oxides and hydroxides on the mild steel surface. This can lead to the creation of a protective layer on the mild steel surface, thereby enhancing corrosion protection and localized inhibition. The work suggested a novel approach to isolate corrosion inhibitors from natural products, particularly agricultural by-products for mild steel in carbon dioxide and chloride ion environment with high inhibition performance.