To assess the properties of the quark–gluon plasma formed in ultrarelativistic ion collisions, the ATLAS experiment at the LHC measures a correlation between the mean transverse momentum and the flow harmonics. The analysis uses data samples of lead–lead and proton–lead collisions obtained at the centre-of-mass energy per nucleon pair of 5.02 TeV, corresponding to total integrated luminosities of 22μb-1 and 28nb-1, respectively. The measurement is performed using a modified Pearson correlation coefficient with the charged-particle tracks on an event-by-event basis. The modified Pearson correlation coefficients for the 2nd-, 3rd-, and 4th-order flow harmonics are measured in the lead–lead collisions as a function of event centrality quantified as the number of charged particles or the number of nucleons participating in the collision. The measurements are performed for several intervals of the charged-particle transverse momentum. The correlation coefficients for all studied harmonics exhibit a strong centrality evolution, which only weakly depends on the charged-particle momentum range. In the proton–lead collisions, the modified Pearson correlation coefficient measured for the 2nd-order flow harmonics shows only weak centrality dependence. The lead-lead data is qualitatively described by the predictions based on the hydrodynamical model.