  A search for flavor-changing neutral-current couplings between a top quark,
an up or charm quark and a $Z$ boson is presented, using proton-proton
collision data at $\sqrt{s} = 13$ TeV collected by the ATLAS detector at the
Large Hadron Collider. The analyzed dataset corresponds to an integrated
luminosity of 139 fb$^{-1}$. The search targets both single-top-quark events
produced as $gq\rightarrow tZ$ (with $q = u, c$) and top-quark-pair events,
with one top quark decaying through the $t \rightarrow Zq$ channel. The
analysis considers events with three leptons (electrons or muons), a $b$-tagged
jet, possible additional jets, and missing transverse momentum. The data are
found to be consistent with the background-only hypothesis and 95%
confidence-level limits on the $t \rightarrow Zq$ branching ratios are set,
assuming only tensor operators of the Standard Model effective field theory
framework contribute to the $tZq$ vertices. These are $6.2 \times 10^{-5}$
($13\times 10^{-5}$) for $t\rightarrow Zu$ ($t\rightarrow Zc$) for a
left-handed $tZq$ coupling, and $6.6 \times 10^{-5}$ ($12\times 10^{-5}$) in
the case of a right-handed coupling. These results are interpreted as 95% CL
upper limits on the strength of corresponding couplings, yielding limits for
$|C_{uW}^{(13)*}|$ and $|C_{uB}^{(13)*}|$ ($|C_{uW}^{(31)}|$ and
$|C_{uB}^{(31)}|$) of 0.15 (0.16), and limits for $|C_{uW}^{(23)*}|$ and
$|C_{uB}^{(23)*}|$ ($|C_{uW}^{(32)}|$ and $|C_{uB}^{(32)}|$) of 0.22 (0.21),
assuming a new-physics energy scale $\Lambda_\text{NP}$ of 1 TeV.
