Cupric oxide is multiferroic at unusually high temperatures. From density functional calculations we find that the low-T magnetic phase is paraelectric, and the higher-T one is ferroelectric with a size and direction of polarization in good agreement with experiments. By mapping the ab initio results on to an effective spin model, we show that the system has a manifold of almost degenerate ground states. In the high-T magnetic state noncollinearity and inversion symmetry breaking stabilize each other via the Dzyaloshinskii-Moriya interaction. This leads to an unconventional mechanism for multiferroicity, with the particular property that nonmagnetic impurities enhance the effect.