Gamma-ray bursts (GRBs) are the most luminous explosions in the Universe, yet the nature and physical properties of their energy sources are far from understood. Very important clues, however, can be inferred by studying the afterglows of these events. We present optical and X-ray observations of GRB 130831A obtained by Swift, Chandra , Skynet, Reionization And Transients Infra-Red camera, Maidanak, International Scientific Optical-Observation Network, Nordic Optical Telescope, Liverpool Telescope and Gran Telescopio Canarias. This burst shows a steep drop in the X-ray light curve at ~=10 5 s after the trigger, with a power-law decay index of α ~ 6. Such a rare behaviour cannot be explained by the standard forward shock (FS) model and indicates that the emission, up to the fast decay at 10 5 s, must be of ‘internal origin’, produced by a dissipation process within an ultrarelativistic outflow. We propose that the source of such an outflow, which must produce the X-ray flux for ~=1 d in the cosmological rest frame, is a newly born magnetar or black hole. After the drop, the faint X-ray afterglow continues with a much shallower decay. The optical emission, on the other hand, shows no break across the X-ray steep decrease, and the late-time decays of both the X-ray and optical are consistent. Using both the X-ray and optical data, we show that the emission after ~=10 5 s can be explained well by the FS model. We model our data to derive the kinetic energy of the ejecta and thus measure the efficiency of the central engine of a GRB with emission of internal origin visible for a long time. Furthermore, we break down the energy budget of this GRB into the prompt emission, the late internal dissipation, the kinetic energy of the relativistic ejecta, and compare it with the energy of the associated supernova, SN 2013 fu.