Numerical models based on the two‐dimensional shallow water equations (2D‐SWE) are routinely used in flood risk management and inundation studies. However, most of these models do not adequately account for vertically confined flow conditions that can appear during inundations, due to the presence of hydraulic structures such as bridges, culverts, or underground river reaches. In this article we propose a new mathematical modification of the standard 2D‐SWE, inspired by the two‐component pressure approach for 1D flows, to address the issue of transient vertically confined flows including transitions between free surface and pressurized conditions. A finite volume discretization to solve the proposed system of equations is proposed and analyzed. Various test cases are used to show the numerical stability and accuracy of the discretization, and to validate the proposed formulation. Results show that the proposed method is numerically stable, accurate, mass conservative, and preserves the C‐property. It can also handle subcritical, supercritical, and transcritical flows under free surface or vertically confined conditions.