In this paper we generalize Brown's spectral distribution measure to a large class of unbounded operators affiliated with a finite von Neumann algebra. Moreover, we compute the Brown measure of all unbounded $R$-diagonal operators in this class. As a particular case, we determine the Brown measure $z=xy^{-1}$, where $(x,y)$ is a circular system in the sense of Voiculescu, and we prove that for all $n\in \mathsf N$, $z^n\in L^p$ if and only if $0<p<\frac{2}{n+1}$.