A numerical model for the three-dimensional simulation of liquid-gas flows with free surfaces is presented. The incompressible Navier-Stokes equations are assumed to hold in the liquid domain. In the gas domain, the velocity is disregarded, the pressure is supposed to be constant in each connected component of the gas domain and follows the ideal gas law. The gas pressure is imposed as a normal force on the liquid-gas interface. An implicit splitting scheme is used to decouple the physical phenomena. Given the gas pressure on the interface, the method described in [J. Comput Phys. 155 (1999) 439; Int. J. Numer. Meth. Fluids 42(7) (2003) 697] is used to track the liquid domain and to compute the velocity and pressure fields in the liquid. Then the connected components of the gas domain are found using an original numbering algorithm. Finally, the gas pressure is updated from the ideal gas law in each connected component of gas. The implementation is validated in the frame of mould filling. Numerical results in two and three space dimensions show that the effect of pressure in the bubbles of gas trapped by the liquid cannot be neglected. (C) 2004 Elsevier Inc. All rights reserved.