In this paper, an optimal adaptive fuzzy sliding mode controller is presented for a class of nonlinear systems. In the proposed control, in the beginning, the boundaries of parametric uncertainties, disturbances and un-modeled dynamics are reduced using a feedback linearization approach. Next, in order to overcome the remaining uncertainties, a sliding mode controller is designed. Mathematical proof shows that the closed-loop system with the proposed control is globally asymptotically stable. Using sliding mode control causes the undesirable chattering phenomenon to occur in the control input. Next, in order to remove the undesirable chattering phenomenon, an adaptive fuzzy approximator is designed to approximate the maximum boundary of the remaining uncertainties. Another mathematical proof shows that the closed-loop system with the proposed control is globally asymptotically stable in the presence of structured and unstructured uncertainties, and external disturbances. Finally, the self-adaptive modified bat algorithm is used to determine the coefficients of the adaptive fuzzy sliding mode control and the coefficients of the membership functions of the adaptive fuzzy approximator. To investigate the performance of the proposed controller, an inverted pendulum system is used as a case study. Simulation results verify the desirable performance of the optimal adaptive fuzzy sliding mode control.