We give a singular control approach to the problem of minimizing an energy functional for measures with given total mass on a compact real interval, when energy is defined in terms of a completely monotone kernel. This problem occurs both in potential theory and when looking for optimal financial order execution strategies under transient price impact. In our setup, measures or order execution strategies are interpreted as singular controls, and the capacitary measure is the unique optimal control. The minimal energy, or equivalently the capacity of the underlying interval, is characterized by means of a nonstandard infinite-dimensional Riccati differential equation, which is analyzed in some detail. We then show that the capacitary measure has two Dirac components at the endpoints of the interval and a continuous Lebesgue density in between. This density can be obtained as the solution of a certain Volterra integral equation of the second kind.