The yield of charged particles opposite to a Z boson with large transverse momentum pT is measured in 260 pb⁻¹ of pp and 1.7 nb⁻¹ of Pb+Pb collision data at 5.02 TeV per nucleon pair recorded with the ATLAS detector at the Large Hadron Collider. The Z boson tag is used to select hard-scattered partons with specific kinematics, and to observe how their showers are modified as they propagate through the quark-gluon plasma created in Pb+Pb collisions. Compared with pp collisions, charged-particle yields in Pb+Pb collisions show significant modifications as a function of charged-particle pTin a way that depends on event centrality and Z boson pT. The data are compared with a variety of theoretical calculations and provide new information about the medium-induced energy loss of partons in a pT regime difficult to measure through other channels.