To get the maximum power point (MPP), the algorithms developed in the literature fail for the most part when the atmospheric conditions vary rapidly. This paper presents the optimization by the swarm particles (PSO) of a sliding mode controller (SMC) to optimize photovoltaic systems (PV) evolving under the conditions of a rapid variation of the sunshine. The stochastic PSO algorithm is used in particular to determine the optimal gains of the sliding mode controller, and this algorithm guarantees the stability and global fast convergence of the system. Efficiency of the proposed hybrid algorithm is proved by using a Solarex MSX-60 module connected to a step-up DC-DC converter supplying a resistive load. The performances are compared to the conventional perturb and observe technique (P&O), PSO, CUCKOO, grey wolf optimization (GWO), and Whale Optimization Algorithm (WOA) in terms of convergence speed, i.e., 0.05 s, tracking speed after extreme change in irradiance 0.03 s, high Ability to track large changes in power before 1 s. Simulation results show that this technique is effective in conditions of a rapid variation of the irradiance.