With the increase in the world population and the rapid developments in technology, the energy demands on modern electricity grids are also rising. In order to meet these demands, power systems are increasingly using renewable energy resources (RESs) in addition to traditional fossil fuel-powered generation units and thus, the structures being implemented in electricity grids are more complex. Consequently, the planning and operation of modern power systems presents important problems, one of which is that of the optimal power flow (OPF). With the integration of RESs, which are usually intermittent in nature, the OPF becomes a more difficult problem to solve. In this study, the OPF problem was designed under different operating cases, considering thermal, wind, solar, small-hydro, and tidal energy systems and load demand uncertainties. The adaptive fitness-distance balance selection-based stochastic fractal search (AFDB-SFS) algorithm was proposed to solve this designed OPF problem. The results for the proposed approach from the experimental studies were statistically evaluated and compared with the results obtained from competitive optimization algorithms in the literature. The comparison demonstrated that the proposed AFDB-SFS algorithm was able to outperform the other algorithms in finding the optimal solution, and convergence speed to the optimal solution. According to the experimental study results, the proposed AFDB-SFS algorithm was able to optimize cost by 5.7362%, 0.0954%, 7.6244%, 0.17871%, 2.4307%, 0.12585%, 2.01729%, 1.7408%, 1.95317%, 3.5486%, 2.2007%, and 1.5203% better than the AO, GBO, GPC, HGS, HHO, RUN, TSO, LSHADE, LSHADE-EPSIN, LSHADE-CNEPSIN, LSHADE-SPACMA, and MadDE optimization algorithms in the proposed OPF problem. The source codes of the AFDB-SFS algorithm (proposed method) can be accessed at this link: https://ch.mathworks.com/matlabcentral/fileexchange/118485-afdb-sfs.