In this article, a new operational matrix method based on shifted Legendre polynomials is presented and analyzed for obtaining numerical spectral solutions of linear and nonlinear second-order boundary value problems. The method is novel and essentially based on reducing the differential equations with their boundary conditions to systems of linear or nonlinear algebraic equations in the expansion coefficients of the sought-for spectral solutions. Linear differential equations are treated by applying the Petrov-Galerkin method, while the nonlinear equations are treated by applying the collocation method. Convergence analysis and some specific illustrative examples include singular, singularly perturbed and Bratu-type equations are considered to ascertain the validity, wide applicability and efficiency of the proposed method. The obtained numerical results are compared favorably with the analytical solutions and are more accurate than those discussed by some other existing techniques in the literature.