Inverse square laws

How does inverse square law of gravity relate to the inverse square law of electromagnetic radiation (e.g. illumination)? How come gravity and EMR propagate identically even though they are different forces?