Context. Protostellar outflows are a crucial ingredient of the star-formation process. However, the physical conditions in the warm outflowing gas are still poorly known. Aims. We present a multi-transition, high spectral resolution CO study of the outflow of the intermediate-mass Class 0 protostar Cep E-mm. The goal is to determine the structure of the outflow and to constrain the physical conditions of the various components in order to understand the origin of the mass-loss phenomenon. Methods. We have observed the J = 12-11, J = 13-12, and J = 16-15 CO lines at high spectral resolution with SOFIA/GREAT and the J = 5-4, J = 9-8, and J = 14-13 CO lines with HIFI/Herschel towards the position of the terminal bowshock HH377 in the southern outflow lobe. These observations were complemented with maps of CO transitions obtained with the IRAM 30 m telescope (J = 1-0, 2-1), the Plateau de Bure interferometer (J = 2-1), and the James Clerk Maxwell Telescope (J = 3-2, 4-3). Results. We identify three main components in the protostellar outflow: the jet, the cavity, and the bowshock, with a typical size of 1.7 × 21 , 4.5 , and 22 × 10 , respectively. In the jet, the emission from the low-J CO lines is dominated by a gas layer at T kin = 80-100 K, column density N(CO) = 9 × 10 16 cm −2 , and density n(H 2 ) = (0.5−1) × 10 5 cm −3 ; the emission of the high-J CO lines arises from a warmer (T kin = 400-750 K), denser (n(H 2 ) = (0.5−1) × 10 6 cm −3 ), lower column density (N(CO) = 1.5 × 10 16 cm −2 ) gas component. Similarly, in the outflow cavity, two components are detected: the emission of the low-J lines is dominated by a gas layer of column density N(CO) = 7 × 10 17 cm −2 at T kin = 55-85 K and density in the range (1−8) × 10 5 cm −3 ; the emission of the high-J lines is dominated by a hot, denser gas layer with T kin = 500-1500 K, n(H 2 ) = (1−5) × 10 6 cm −3 , and N(CO) = 6 × 10 16 cm −2 . A temperature gradient as a function of the velocity is found in the high-excitation gas component. In the terminal bowshock HH377, we detect gas of moderate excitation, with a temperature in the range T kin ≈ 400-500 K, density n(H 2 ) (1−2) × 10 6 cm −3 and column density N(CO) = 10 17 cm −2 . The amounts of momentum carried away in the jet and in the entrained ambient medium are similar. Comparison with time-dependent shock models shows that the hot gas emission in the jet is well accounted for by a magnetized shock with an age of 220-740 yr propagating at 20-30 km s −1 in a medium of density n(H 2 ) = (0.5−1) × 10 5 cm −3 , consistent with that of the bulk material. Conclusions. The Cep E protostellar outflow appears to be a convincing case of jet bowshock driven outflow. Our observations trace the recent impact of the protostellar jet into the ambient cloud, produing a non-stationary magnetized shock, which drives the formation of an outflow cavity.