A Legendre rational spectral method is proposed for the nonlinear Klein-Gordon equation on the whole line. Its stability and convergence are proved. Numerical results coincides well with the theoretical analysis and demonstrate the e?ciency of this approach.