We present KETJU, a new extension of the widely-used smoothed particle hydrodynamics simulation code GADGET-3. The key feature of the code is the inclusion of algorithmically regularized regions around every supermassive black hole (SMBH). This allows for simultaneously following global galactic-scale dynamical and astrophysical processes, while solving the dynamics of SMBHs, SMBH binaries and surrounding stellar systems at sub-parsec scales. The KETJU code includes PostNewtonian terms in the equations of motions of the SMBHs which enables a new SMBH merger criterion based on the gravitational wave coalescence timescale pushing the merger separation of SMBHs down to ∼ 0.005 pc. We test the performance of our code by comparison to NBODY7 and rVINE. We set up dynamically stable multi-component merger progenitor galaxies to study the SMBH binary evolution during galaxy mergers. In our simulation sample the SMBH binaries do not suffer from the final-parsec problem, which we attribute to the non-spherical shape of the merger remnants. For bulge-only models, the hardening rate decreases with increasing resolution, whereas for models which in addition include massive dark matter halos the SMBH binary hardening rate becomes practically independent of the mass resolution of the stellar bulge. The SMBHs coalesce on average 200 Myr after the formation of the SMBH binary. However, small differences in the initial SMBH binary eccentricities can result in large differences in the SMBH coalescence times. Finally, we discuss the future prospects of KETJU, which allows for a straightforward inclusion of gas physics in the simulations.