When drilling or exploiting fractured formations, gas fluid displacement and invasion often occur, and gas invasion is very subtle and difficult to find. The gas in the fracture enters the wellbore and arrives near the wellhead with the drilling fluid. Improper treatment may lead to serious accidents such as lost circulation and blowout. In this study, using computational fluid dynamics (CFD) simulation software for modeling and grid generation, based on the volume of fluid (VOF) method, the gas invasion behavior under different conditions was simulated to explore the flow process and characteristics of gas invasion, and the effects of different drilling fluid properties and fracture morphology on gas invasion were analyzed. The experimental results show that the drilling fluid enters the fracture to compress the gas, making the pressure in the fracture greater than that in the wellbore, thus leading to the occurrence of gas invasion. The viscosity and density of the drilling fluid have different effects on the gas invasion process. The higher the viscosity, the smaller the possibility of gas invasion. However, when the viscosity of the drilling fluid gradually increases from 10–50 MPa·s, the change of gas invasion rate is small, all within 1.0–1.2 m/s. The higher the density, the more conducive to the occurrence of gas invasion. The inlet pressure has no obvious effect on the occurrence of gas invasion, and the occurrence time of the gas invasion fluctuates in 0.35 s at 0.5–2.5 MPa. With the increase in the fracture width and length, the possibility of gas invasion decreases, but there is an extreme value for the fracture height. The time of gas invasion does not change beyond this extreme value. When the fracture height is 100–700 mm, the time of gas invasion increases with the increase in the height; when the height is 700–900 mm, the gas invasion time does not change. These results provide a practical and effective method for enhancing oil recovery, preventing and treating gas invasion in gas–liquid flooding.