The original result is Newton's shell theorem. Since we can break up a spherically symmetric distribution into spherically symmetric concentric shells, it is sufficient to consider the corresponding statement for one such shell: for each shell taken individually, there is no force on a particle inside, and a force on a particle outside as if all of the mass was concentrated at the center.
This can be derived directly from Newton's law of gravitation through careful integration (one such derivation in the wiki link above), but probably the cleanest method is rather through Gauss's law, which states that the divergence of the gravitational field is proportional to the mass density:
$$\nabla\cdot\mathbf{g} = -4\pi G\rho\text{.}$$ It's just the same as the law for the electric field because Coulomb's law and Newton's law of gravitation have the same form (with $\epsilon_0\mapsto-(4\pi G)^{-1}$). By the divergence theorem, the flux through a surface enclosing volume $V$ is proportional to the enclosed mass:
$$\int_{\partial V}\mathbf{g}\cdot\mathrm{d}\mathbf{S} = \int_V\nabla\cdot\mathbf{g}\,\mathrm{d}V = -4\pi GM_\text{enc}\text{,}$$
since then we are just integrating the density over the entire volume.
But each shell should have a spherically symmetric gravitational field, so $\mathbf{g} = g\hat{\mathbf{r}}$, where $g = g(r)$ is a function of radius only. Since the Gaussian surface has constant $r$, all we get is $g(r)$ times its area:
$$-4\pi GM_\text{enc} = g(r)\int_{\partial{V}}\mathrm{d}\mathbf{S} = 4\pi r^2 g(r)\text{,}$$
and it follows that
$$\mathbf{g} = -\frac{GM_\text{enc}}{r^2}\text{.}$$
Obviously, if the particle is inside the shell, the Gaussian surface encloses no mass, since again we are considering each shell individually. The total effect of a spherically symmetric distribution would just be the sum of the effects of each individual shell.