Rare asteroidal vesicular basalts have previously been thought to form in surficial lava flows with CO as the vesicle-forming gas. However, vesicular lava flows are unlikely on small, airless bodies such as asteroids. To unravel the origin of these rocks, we analyzed vesicle sizes and abundances for two angrites and two eucrites using high-resolution X-ray computed tomography and conducted numerical modeling of bubble formation in a dike of ascending magma. Modeling results indicate that thin (< 30 cm wide) dikes are trapped at 5 km depth where 75 ppm of CO and CO2 contribute equally to vesicle formation. Vesicular eucrites were metamorphosed in this deep-seated environment, the gas was lost, and they were excavated by impacts.