Measurements of both the inclusive and differential production cross sections of a top-quark–antiquark pair in association with a Z boson (tt¯ Z) are presented. The measurements are performed by targeting final states with three or four isolated leptons (electrons or muons) and are based on s=13 TeV proton–proton collision data with an integrated luminosity of 139 fb - 1, recorded from 2015 to 2018 with the ATLAS detector at the CERN Large Hadron Collider. The inclusive cross section is measured to be σtt¯Z= 0.99 ± 0.05 (stat.) ±0.08 (syst.) pb, in agreement with the most precise theoretical predictions. The differential measurements are presented as a function of a number of kinematic variables which probe the kinematics of the tt¯ Z system. Both absolute and normalised differential cross-section measurements are performed at particle and parton levels for specific fiducial volumes and are compared with theoretical predictions at different levels of precision, based on a χ2/ ndf and p value computation. Overall, good agreement is observed between the unfolded data and the predictions.