To every elliptic Calabi-Yau threefold with a section $X$ there can be associated a Lie group $G$ and a representation $\rho$ of that group. The group is determined from the Weierstrass model, which has singularities that are generically rational double points; these double points lead to local factors of $G$ which are either the corresponding A-D-E groups or some associated non-simply laced groups. The representation $\rho$ is a sum of representations coming from the local factors of $G$, and of other representations which can be associated to the points at which the singularities are worse than generic. This construction first arose in physics, and the requirement of anomaly cancellation in the associated physical theory makes some surprising predictions about the connection between $X$ and $\rho$. In particular, an explicit formula (in terms of $\rho$) for the Euler characteristic of $X$ is predicted. We give a purely mathematical proof of that formula in this paper, introducing along the way a new invariant of elliptic Calabi-Yau threefolds. We also verify the other geometric predictions which are consequences of anomaly cancellation, under some (mild) hypotheses about the types of singularities which occur. As a byproduct we also discover a novel relation between the Coxeter number and the rank in the case of the simply laced groups in the ``exceptional series'' studied by Deligne.