The Sliding Mode Controllers (SMCs) are considered among the most common stabilizer and controllers used with robotic systems due to their robust nonlinear scheme designed to control nonlinear systems. SMCs are insensitive to external disturbance and system parameters variations. Although the SMC is an adaptive and model-based controller, some of its values need to be determined precisely. In this paper, an Optimal Sliding Mode Controller (OSMC) is suggested based on Whale Optimization Algorithm (WOA) to control a two-link lower limb rehabilitation robot. This controller has two parts, the equivalent part, and the supervisory controller part. The stability assurance of the controlled rehabilitation robot is analyzed based on Lyapunov stability. The WO algorithm is used to determine optimal parameters for the suggested SMC. Simulation results of two tested trajectories (linear step signal and nonlinear sine signal) demonstrate the effectiveness of the suggested OSMC with fast response, very small overshoot, and minimum steady-state error.