Measurements of longitudinal flow correlations are presented for charged particles in the pseudorapidity range using 7 and 470 of Pb+Pb collisions at and 5.02 TeV, respectively, recorded by the ATLAS detector at the LHC. It is found that the correlation between the harmonic flow coefficients measured in two separated intervals does not factorise into the product of single-particle coefficients, and this breaking of factorisation, or flow decorrelation, increases linearly with the separation between the intervals. The flow decorrelation is stronger at 2.76 TeV than at 5.02 TeV. Higher-order moments of the correlations are also measured, and the corresponding linear coefficients for the -moment of the are found to be proportional to k for , but not for . The decorrelation effect is separated into contributions from the magnitude of and the event-plane orientation, each as a function of . These two contributions are found to be comparable. The longitudinal flow correlations are also measured between of different order in n. The decorrelations of and are found to be independent of each other, while the decorrelations of and are found to be driven by the nonlinear contribution from and , respectively.