This paper proposes a modified swing control for a nonlinear inverted pendulum system by utilizing the sliding mode controller based on the on-line tuningBeesalgorithm as speed of optimization and accuracy of results. The goal of the proposed nonlinear controller is to obtainthe optimal force control action for the pendulumcart in order to stabilize the pendulum in the inverted position precisely and quickly.The optimal parameters of the nonlinear controller are on-line tuned by Bees algorithm and guided by Lyapunov stability criterionto reduce the amplitude of the sliding mode signum function in order to eliminate the chattering phenomena and make the smoothness control action.Matlab simulation results confirm the validity of the proposed controller algorithm in terms offast dynamic response, minimizing the pendulum’s angle tracking error to the zero radianat 2.5 second and obtaining the optimal and smooth force control action without saturation state, with the minimum number of fitness evaluation of the algorithm.