This work addresses the problem of the optimal integration of distributed photovoltaic generators (PV) and distributed static compensators (D-STATCOM) in electrical distribution systems (EDS), a complex challenge due to the nonlinearity of the mathematical models that describe both their operation and the integration of operational and investment costs, while adhering to the operational constraints of these devices. To solve this problem, a two-stage solution methodology is proposed: the first stage employs the Crow Search Algorithm (CSA), and the second utilizes a matrix power flow method based on successive approximations. The main objective is to minimize operational and annual investment costs through the optimal operation of photovoltaic generators and D-STATCOM devices. Although various researchers have proposed similar methodologies with the same goal, many of these studies lack robustness and do not include statistical analyses to evaluate the quality of the solutions obtained. In this study, a comparative statistical analysis is conducted with different optimization algorithms from specialized literature, including the Vortex Search Algorithm (VSA), the Sine Cosine Algorithm (SCA), a continuous Genetic Algorithm (GA), and the Particle Swarm Optimization Algorithm (PSO). To validate the proposed methodology, test systems with 33 and 69 nodes were used, incorporating variations in energy demand and photovoltaic generation from a region in Colombia. The results demonstrate that the proposed method, based on the Crow Search Algorithm, outperforms other approaches in terms of the quality of the best solution found, the average solution, and the standard deviation of the results. The comparative statistical analysis was carried out by executing the methodology 100 times in the MATLAB programming environment, confirming the superiority and consistency of the proposed approach.