A family of smooth invariant tori of a Hamiltonian system can be parameterized by the values of the actions or the frequencies. These parameterizations are related by the action-frequency map. The purpose of this paper is to show that when the action-frequency map is degenerate, it signals a homoclinic bifurcation. Remarkably, the nonlinear properties of this homoclinic bifurcation to invariant tori are determined by the curvature of the action-frequency map. A homoclinic angle is also generated which is analogous to a Hannay-Berry phase shift. The theory is constructive and so can usefully be combined with computation. Some implications for quantization, and the generation of solitary waves are also discussed.