This paper presents a measurement of jet fragmentation functions in 0.49 nb-1 of Pb+Pb collisions and 25 pb-1 of pp collisions at sNN=5.02 TeV collected in 2015 with the ATLAS detector at the LHC. These measurements provide insight into the jet quenching process in the quark-gluon plasma created in the aftermath of ultrarelativistic collisions between two nuclei. The modifications to the jet fragmentation functions are quantified by dividing the measurements in Pb+Pb collisions by baseline measurements in pp collisions. This ratio is studied as a function of the transverse momentum of the jet, the jet rapidity, and the centrality of the collision. In both collision systems, the jet fragmentation functions are measured for jets with transverse momentum between 126 and 398 GeV and with an absolute value of jet rapidity less than 2.1. An enhancement of particles carrying a small fraction of the jet momentum is observed, which increases with centrality and with increasing jet transverse momentum. Yields of particles carrying a very large fraction of the jet momentum are also observed to be enhanced. Between these two enhancements of the fragmentation functions a suppression of particles carrying an intermediate fraction of the jet momentum is observed in Pb+Pb collisions. A small dependence of the modifications on jet rapidity is observed.