A Fourier analysis-type identity arising in potential theory

I have recently been learning about potential theory in the complex plane, and I would like to understand why the following proposition is true:

Suppose $f: \mathbb C \to \mathbb R$ is smooth, compactly supported, and satisfies $$\int \! f(z) \, d^2 \! z = 0.$$ Then $$\iint \! f(z)f(w) \log |z-w|^{-1} \, d^2 \! z \, d^2 \! w = 2\pi \int \! \left| \frac{\widehat{f}(p)}{p} \right|^2 \, d^2 \! p.$$

Remarks: 1) I use $\widehat{\cdot}$ to denote the Fourier transform, and I use the notation $\int \! h(z) \, d^2 \! z$ to mean the integral of $h$ against two-dimensional Lebesgue measure on $\mathbb C$. 2) The assumption that $f$ be smooth (infinitely differentiable) seems excessive to me, but I have no need to weaken this hypothesis.

My motivation for understanding this identity comes from the fact that (in the notes from which I am learning) it is the key ingredient in the proof of the uniqueness of equilibrium measures on compact sets, that is, Borel probability measures supported in a fixed compact set $K$ which minimize the energy functional $$E(\mu) = \iint_{K^2} \! \log|z-w|^{-1} \, d\mu(z) \, d\mu(w).$$

However, the notes which I am using to learn potential theory assert this identity without proof or reference, and it is unclear to me why it should be true.

In particular, one can use this identity to prove that $$E (\mu - \nu) = 2\pi \int \frac{| \widehat{\mu}(p) - \widehat{\nu}(p) |^2}{|p|^2} \, d^2 \! p,$$

for all $\mu, \nu$. This can then be used to show that $$E\left(\frac{1}{2}(\mu + \nu)\right) \leq \frac{1}{2} ( E(\mu) + E(\nu) )$$ with equality if and only if $\mu = \nu$. Uniqueness of a minimizer is then obvious.

One could make a fair case that this is easy/trivial/not really research level math, but I am interested in applications of potential theory to other areas of analysis, so it would be beneficial to understand the foundations.

-
Compute the inner product of $f$ and $\Delta^{-1} f$ using (a) the fundamental solution for the Laplacian in two dimensions (en.wikipedia.org/wiki/Newtonian_potential); or (b) the Fourier transform. –  Terry Tao Jul 31 '13 at 22:55