Cavitation refers to the formation and collapse of vapor bubbles near solid boundaries in high-speed flows, such as ship propellers and pumps. During this process, cavitation bubbles focus fluid energy on the solid surface by forming high-speed jets, leading to damage and downtime of machinery. In response, numerous surface treatments to counteract this effect have been explored, including perfluorinated coatings and surface hardening, but they all succumb to cavitation erosion eventually. Here, we report on biomimetic gas-entrapping microtextured surfaces (GEMS) that robustly entrap air when immersed in water regardless of the wetting nature of the substrate. Crucially, the entrapment of air inside the cavities repels cavitation bubbles away from the surface, thereby preventing cavitation damage. We provide mechanistic insights by treating the system as a potential flow problem of a multi-bubble system. Our findings present a possible avenue for mitigating cavitation erosion through the application of inexpensive and environmentally friendly materials.