We prove existence of global and conservative solutions of the Cauchy problem for the nonlinear partial differential equation u-u+f(-f(+(g(u)+1/2 >f(=0 where f is strictly convex or concave and g is locally uniformly Lipschitz. This includes the Camassa-Holm equation ( f(u)=u/2 and g(u)=κu+u) as well as the hyperelastic-rod wave equation ( f(u)=γu/2 and g(u)=(3-γ)u/2) as special cases. It is shown that the problem is well-posed for initial data in H(R) if one includes a Radon measure that corresponds to the energy of the system with the initial data. The solution is energy preserving. Stability is proved both with respect to initial data and the functions f and g. The proof uses an equivalent reformulation of the equation in terms of Lagrangian coordinates.