The purpose of the current article is to analyze the influence of magnetohydrodynamics (MHD) on the pipe flow of a third-grade fluid with variable viscosity. In addition, the heat transfer characteristic is taken into account. Due to the nonlinear, coupled and highly complicated nature of the governing equations, finding an analytical solution is not easy. We obtained the expressions for the velocity and temperature using the homotopy analysis method (HAM). The sketched graphs describe the features of the physical parameters involved in the solution.