Pore-scale simulations of quenching, acceleration, and transition to detonation of gaseous hydrogen explosions by metal foams were performed. The model solves the three dimensional compressible reactive Navier-Stokes equations with detailed chemistry in a closed square channel with a metal foam placed inside. The structures of the foam were fully resolved using an immersed boundary method. Stoichiometric mixtures of hydrogen-oxygen and hydrogen-air were considered. An explosion in the channel was initiated with a high-pressure and high-temperature spark. The simulation results show that the explosion can be quenched, accelerate, or transition to detonation depending on the foam pores-per-inch (PPI). Hydrogen-air explosions were quenched with foams of ∼39 PPI or higher due to heat losses from the flame, which is consistent with experimental observations. The explosion was not quenched by foams with low PPI. Instead the low PPI foams exacerbated the explosion by causing flame acceleration. Worse, a 78 PPI foam caused a stoichiometric H2 and O2 mixture to transition to detonation. Hydraulic resistance due to products venting away from the flame surface was found to produce strong pressure gradients within the foam. This causes a self-pressurizing effect that grows as the flame propagates further into the foam. The pressure within the foam grows and steepens into a shock. The shock initiated the detonation by a Mach reflection, which is similar to deflagration-to-detonation transition mechanisms in traditional obstacle-laden channels. Statement of SignificanceMetal foam structures are often used as devices to inhibit flames in scenarios where explosion hazards are a concern. Direct numerical simulations were performed to increase understanding of how flames and explosions interact with metal foams. The simulation results show that high pores-per-inch (PPI) foams quench the explosion by removing heat from the flame. Lower PPI foams can have the opposite effect and exacerbate the explosion by promoting flame acceleration or even transition to detonation. Flames self-pressurize as they propagate through low PPI foams due to hydrodynamic friction and gas-dynamic effects from flowing product gases. In extreme cases, the pressure waves near the flame can steepen into a shock and initiate a detonation. These results indicate that improperly selected metal foam flame arresters can exacerbate the explosion.