This article introduces a new attempt of utilizing the sunflower optimization (SFO) algorithm in solving the problem of optimal power flow (OPF) in the field of power systems. The principle target is to optimize the generating units' fuel cost under the system constraints. At initial stage, the objective function is solved to find the optimal siting of Distributed Generation (DG) units within the system under study. Then, different scenarios are performed to solve the OPF problem including and excluding DG units. The generators' real output power defines the exploration field for the OPF problem. The SFO algorithm is used to minimize the fitness function and yields the best solutions of the problem. More than one electric grid is tested to check the validity of the proposed algorithm such as the IEEE 14-bus, and 30-bus networks. Simulations included different scenarios are implemented in these two networks. To obtain a realistic result, real daily load curve is considered in this study. The results of simulations are investigated and analyzed. Results confirm the flexibility, validation, and applicability of the introduced SFO-based OPF methodology when compared with the genetic algorithm. INDEX TERMS Optimal power flow, optimization, power systems, renewable energy.