Inclusive and differential measurements of the top-antitop ($t\bar{t}$) charge asymmetry $A_\text{C}^{t\bar{t}}$ and the leptonic asymmetry $A_\text{C}^{\ell\bar{\ell}}$ are presented in proton-proton collisions at $\sqrt{s} = 13$ TeV recorded by the ATLAS experiment at the CERN Large Hadron Collider. The measurement uses the complete Run 2 dataset, corresponding to an integrated luminosity of 139 fb$^{-1}$, combines data in the single-lepton and dilepton channels, and employs reconstruction techniques adapted to both the resolved and boosted topologies. A Bayesian unfolding procedure is performed to correct for detector resolution and acceptance effects. The combined inclusive $t\bar{t}$ charge asymmetry is measured to be $A_\text{C}^{t\bar{t}} = 0.0068 \pm 0.0015$, which differs from zero by 4.7 standard deviations. Differential measurements are performed as a function of the invariant mass, transverse momentum and longitudinal boost of the $t\bar{t}$ system. Both the inclusive and differential measurements are found to be compatible with the Standard Model predictions, at next-to-next-to-leading order in quantum chromodynamics perturbation theory with next-to-leading-order electroweak corrections. The measurements are interpreted in the framework of the Standard Model effective field theory, placing competitive bounds on several Wilson coefficients.