A numerical algorithm of solving the three-dimensional system of Navier-Stokes equations to simulate free surface waves and flows with gravity is presented. The main problem here is to ensure that the gravity force is properly accounted in the presence of discontinuities in the medium density. The task is made more complicated due the use of unstructured computational grids with collocated placement of unknown quantities and splitting algorithms based on SIMPLE-type methods. To obtain correctly the hydrostatic pressure, it is suggested that the contribution of the gravitational force in the equation for pressure should be distinguished explicitly; the latter being calculated by using the solution of the two-phase medium gravitational balance problem. To ensure the balance of the gravity force and the pressure gradient in the case of rest an algorithm in which the pressure gradient in the equation of motion is replaced by a modification considering the gravitational force action is suggested. This method is demonstrated by the example of tsunami wave propagation in the real water area of the World Ocean. © 2017 - TSUNAMI SOCIETY INTERNATIONAL.