The giant planet atmospheres exhibit alternating prograde (eastward) and retrograde (westward) jets of different speeds and widths, with an equatorial jet that is prograde on Jupiter and Saturn and retrograde on Uranus and Neptune. The jets are variously thought to be driven by differential radiative heating of the upper atmosphere or by intrinsic heat fluxes emanating from the deep interior. But existing models cannot account for the different flow configurations on the giant planets in an energetically consistent manner. Here a three-dimensional general circulation model is used to show that the different flow configurations can be reproduced by mechanisms universal across the giant planets if differences in their radiative heating and intrinsic heat fluxes are taken into account. Whether the equatorial jet is prograde or retrograde depends on whether the deep intrinsic heat fluxes are strong enough that convection penetrates into the upper troposphere and generates strong equatorial Rossby waves there. Prograde equatorial jets result if convective Rossby wave generation is strong and low-latitude angular momentum flux divergence owing to baroclinic eddies generated off the equator is sufficiently weak (Jupiter and Saturn). Retrograde equatorial jets result if either convective Rossby wave generation is weak or absent (Uranus) or low-latitude angular momentum flux divergence owing to baroclinic eddies is sufficiently strong (Neptune). The different speeds and widths of the off-equatorial jets depend, among other factors, on the differential radiative heating of the atmosphere and the altitude of the jets, which are vertically sheared. The simulations have closed energy and angular momentum balances that are consistent with observations of the giant planets.