When a current $I$ runs through a wire all the electrical energy is used up as given by the relation, $H=I^2Rt$, but when we move the current through a magnetic field we get torque.

So if all electrical energy is used up in heat how mechanical work is done ?