A solar-coronal magnetic loop is rooted in the photosphere, where motions shuffle the footpoints of the field, generating currents in the corona. The dissipation of these currents provides a possible mechanism for heating the solar corona. A theory is described based on a generalization of Taylor's hypothesis, predicting that as the loop is twisted up, it relaxes towards a minimum-energy state V × B = μB. The footpoint motions inject helicity as well as energy, and the evolution is determined through a helicity-injection equation. The loop is modelled as a straight magnetic-flux tube, with twisting motions at the ends, confined by a constant external pressure at the curved surface, which is a free boundary. The problem of the loop evolution in response to given footpoint motions is solved, and an interesting example of multiple equilibria arises. The heating rate is calculated for an almost-potential loop. The model may also be regarded as representing a laboratory experiment: in particular, a simple idealization of a spheromak, with the footpoint motions replaced by an applied voltage.