In this study, the structural and electronic properties of a boron nitride nanocone (BNNC) with 120° disclination were investigated using density functional theory calculations. In the considered model, there are one tetragonal ring and 56 hexagonal rings, with the mouth of nanocone saturated by the hydrogen atoms. In the second step, with making defect in boron nitride nanocone and transverse cutting on its apex, the structure similar to porphyrin was induced in preliminary boron nitride nanocone and the P-BNNC compound was produced. In the third step, the Mg2+ ion was placed in the center of the produced core in P-BNNC and the chlorophyll like structure (Mg- P-BNNC) was formed. In the final step, the interactions between CO2, CO, H2 and O2 gas molecules and the exterior and interior surface of Mg- P-BNNC compound was studied. The CO2 and H2 gas molecules adsorbed only on the Mg metal atom on the exterior SITE but, the CO molecule was adsorbed from both the exterior and interior SITE of Mg- P-BNNC. However, the O2 gas molecule has high adsorption only from the interior SITE of Mg- P-BNNC. With the adsorption of CO2, CO and H2 gases on Mg- P-BNNC, the band gap is approximately constant and so, the conductivity of Mg- P-BNNC molecule has not significantly changed. The noticeable point is that the amount of Mg- P-BNNC band gap, as well as conductivity, has significant change with the adsorption of O2 gas on its interior SITE. So, the Mg- P-BNNC is the good and selective sensor for the O2 gas in the presence of CO2, CO and H2 gases. The Density of State (DOS) and Natural Bond Orbital (NBO) calculations have confirmed the above results.