Tetragonal graphene nano-capsule (TGC), a novel stable carbon allotrope of sp2 hybridization is designed and doped with phosphorus (P) to study the O3 and SO2 gas sensitivity via density functional theory calculation. Real frequencies verified the natural existence of both TGC and P-doped TGC (PTGC). Both TGC and PTGC suffer structural deformations due to interaction with O3 and SO2 gases. The amount of charge transfer from the adsorbent to the gas molecule is significantly greater for O3 adsorption than SO2 adsorption. The adsorption energies for TGC + O3 and PTGC + O3 complexes are − 3.46 and − 4.34 eV respectively, whereas for TGC + SO2 and PTGC + SO2 complexes the value decreased to − 0.29 and − 0.30 eV respectively. The dissociation of O3 is observed via interaction with PTGC. A significant variation in electronic energy gap and conductivity results from gas adsorption which can provide efficient electrical responses via gas adsorption. The blue/red shift in the optical response proved to be a way of detecting the types of adsorbed gases. The adsorption of O3 is exothermic and spontaneous whereas the adsorption of SO2 is endothermic and non-spontaneous. The negative change in entropy verifies the thermodynamic stability of all the complexes. QTAIM analysis reveals strong covalent or partial covalent interactions between absorbent and adsorbate. The significant variation in electrical and optical response with optimal adsorbent-gas interaction strength makes both TGC and PTGC promising candidates for O3 and SO2 sensing.