In this paper, the effect of variable magnetic field on the forced-convection boundary-layer of MHD Al2O3–water nanofluid flow over a porous nonlinearly stretching flat plate is investigated using Optimal Collocation Method (OCM) and fourth order Runge–Kutta numerical method. This is the first time that CM method is developed for the problems with coupled equations which have infinite boundary condition. Comparison between OCM and numerical method shows that OCM is an exact and high efficient method for solving these kinds of problems. The influence of the nanofluid volume fraction (φ) and magnetic parameter (Mn) on non-dimensional temperature and velocity profiles are investigated. As an important outcome, by increasing Mn number, thermal boundary layer thickness significantly increased but increasing the nanofluid volume fraction hasn’t very sensible effect on it. Also it is understandable that the temperature of the fluid decreases by increasing suction parameter.