This paper discusses the discrete analogue of the gradient of a function and shows how discrete gradients can be used in the numerical integration of ordinary differential equations (ODEs). Given an ODE and one or more first integrals (i.e. constants of the motion) and/or Lyapunov functions, it is shown that the ODE can be rewritten as a ‘linear–gradient system’. Discrete gradients are used to construct discrete approximations to the ODE which preserve the first integrals and Lyapunov functions exactly. The method applies to all Hamiltonian, Poisson and gradient systems, and also to many dissipative systems (those with a known first integral or Lyapunov function).