To comprehensively understand the explosion risk in underground energy transportation tunnels, this study employed computational fluid dynamics technology and finite element simulation to numerically analyze the potential impact of an accidental explosion for a specific oil and gas pipeline in China and the potential damage risk to nearby buildings. Furthermore, the study investigated the effects of tunnel inner diameter (d = 4.25 m, 6.5 m), tunnel length (L = 4 km, 8 km, 16 km), and soil depth (primarily Lsoil = 20 m, 30 m, 40 m) on explosion dynamics and on structural response characteristics. The findings indicated that as the tunnel length and inner diameter increased, the maximum explosion overpressure gradually rose and the peak arrival time was delayed, especially when d = 4.25 m; with the increase in L, the maximum explosion overpressure rapidly increased from 1.03 MPa to 2.12 MPa. However, when d = 6.5 m, the maximum explosion overpressure increased significantly by 72.8% from 1.25 MPa. Evidently, compared to the change in tunnel inner diameter, tunnel length has a more significant effect on the increase in explosion risk. According to the principle of maximum explosion risk, based on the peak explosion overpressure of 2.16 MPa under various conditions and the TNT equivalent calculation formula, the TNT explosion equivalent of a single section of the tunnel was determined to be 1.52 kg. This theoretical result is further supported by the AUTODYN 15.0 software simulation result of 2.39 MPa (error < 10%). As the soil depth increased, the distance between the building and the explosion source also increased. Consequently, the vibration peak acceleration and velocity gradually decreased, and the peak arrival time was delayed. In comparison to a soil depth of 10 m, the vibration acceleration at soil depths of 20 m and 30 m decreased by 81.3% and 91.7%, respectively. When the soil depth was 10 m, the building was at critical risk of vibration damage.