  The initial energy density distribution and fluctuation in the transverse
direction lead to anisotropic flows of final hadrons through collective
expansion in high-energy heavy-ion collisions. Fluctuations along the
longitudinal direction, on the other hand, can result in decorrelation of
anisotropic flows in different regions of pseudo rapidity ($\eta$).
Decorrelation of the $2$nd and $3$rd order anisotropic flows with different
$\eta$ gaps for final charged hadrons in high-energy heavy-ion collisions is
studied in an event-by-event (3+1)D ideal hydrodynamic model with fully
fluctuating initial conditions from A Multi-Phase Transport (AMPT) model. The
decorrelation of anisotropic flows of final hadrons with large $\eta$ gaps are
found to originate from the spatial decorrelation along the longitudinal
direction in the AMPT initial conditions through hydrodynamic evolution. The
decorrelation is found to consist of both a linear twist and random fluctuation
of the event-plane angles. The agreement between our results and recent CMS
data in most centralities suggests that the string-like mechanism of initial
parton production in AMPT model captures the initial longitudinal fluctuation
that is responsible for the measured decorrelation of anisotropic flows in
Pb+Pb collisions at LHC. Our predictions for Au+Au collisions at the highest
RHIC energy show stronger longitudinal decorrelation, indicating larger
longitudinal fluctuations at lower beam energies. Our study also calls into
question some of the current experimental methods for measuring anisotropic
flows and extraction of transport coefficients through comparisons to
hydrodynamic simulations that do not include longitudinal fluctuations.
