The authors propose an optimal contract mechanism under moral hazard in discrete-time dynamic electric power networks. As the utility (system operator) cannot adjust the control input of the agents (end-users) directly in real time out of respect for individual decision–making, the agents’ control input maximising their own profit does not always maximise social welfare. To avoid the issue, the authors introduce an aggregator as intermediary between the utility and the agents. The aggregator pays compensation for defective ancillary services, which are caused by random disturbance and the agents’ voluntary control. To reduce the compensation risk, the authors first present an optimal incentive/control contract problem for the aggregator's compensation. The problem is usually regarded as a principal-agent problem under moral hazard in contract theory. However, it is generally difficult to solve a contract problem with dynamics expressed as discrete-time simultaneous Bellman equations and a hierarchical control structure as a Stackelberg game. The authors next show that the problem can be solved by regarding it as a linear-exponential-quadratic-Gaussian dynamic game and employing a numerical optimisation technique. Due to the ex-ante appropriate payment contract, the agents select control inputs preferable for the aggregator. The effectiveness of the proposed contract mechanism is finally demonstrated through simulation.