Consider a point source with a sphere of arbitrary radius enclosing it. Both electric fields and gravitational fields obey the same basic differential equation:
$$\nabla \cdot F = \rho$$
for some field $F$ and some source $\rho$. The divergence theorem tells us that fields obeying this equation also obey
$$\int_{V} \rho \, dV = \oint_{\partial V} F \cdot dS$$
This is a mathematical consequence of obeying the first equation. This integral theorem must hold for all volumes enclosing our point source. That is to say, these integrals are constant--the left hand integral tells us the total charge or mass, and we have only one point source, so as long as the volume contains the point source, the integral must have a constant value regardless of size.
On the other hand, we've chosen a sphere for our surface of integration on the right-hand side. By symmetry, we conclude that this integral reduces to $4\pi R^2 |F(R)|$. For this to be constant, $F(R)$ must fall off as $1/R^2$.
In different numbers of dimensions, the dropoff will have a different form. For instance, in 1d there's no dropoff at all (cf. the electric field from an infinite sheet of charge).