The secular approximation for the evolution of hierarchical triple configurations has proven to be very useful in many astrophysical contexts, from planetary to triple-star systems. In this approximation the orbits may change shape and orientation, on time-scales longer than the orbital time-scales, but the semimajor axes are constant. For example, for highly inclined triple systems, the Kozai–Lidov mechanism can produce large-amplitude oscillations of the eccentricities and inclinations. Here we revisit the secular dynamics of hierarchical triple systems. We derive the secular evolution equations to octupole order in Hamiltonian perturbation theory. Our derivation corrects an error in some previous treatments of the problem that implicitly assumed a conservation of the z-component of the angular momentum of the inner orbit (i.e. parallel to the total angular momentum of the system). Already to quadrupole order, our results show new behaviours including the possibility for a system to oscillate from prograde to retrograde orbits. At the octupole order, for an eccentric outer orbit, the inner orbit can reach extremely high eccentricities and undergo chaotic flips in its orientation. We discuss applications to a variety of astrophysical systems, from stellar triples to merging compact binaries and planetary systems. Our results agree with those of previous studies done to quadrupole order only in the limit in which one of the inner two bodies is a massless test particle and the outer orbit is circular; our results agree with previous studies at octupole order for the eccentricity evolution, but not for the inclination evolution.