The problem of the optimal placement and sizing of renewable generation sources based on photovoltaic (PV) technology in electrical distribution grids operated in medium-voltage levels was studied in this research. This optimization problem is from the mixed-integer nonlinear programming (MINLP) model family. Solving this model was achieved by implementing a master–slave optimization approach, where the master–slave corresponded to the application of the modified gradient-based metaheuristic optimizer (MGbMO) and the slave stage corresponded to the application of the successive approximation power flow method. In the master stage, the problem of the optimal placement and sizing of the PV sources was solved using a discrete–continuous codification, while the slave stage was used to calculate the objective function value regarding the energy purchasing costs in terminals of the substation, as well as to verify that the voltage profiles and the power generations were within their allowed bounds. The numerical results of the proposed MGbMO in the IEEE 34-bus system demonstrated its efficiency when compared with different metaheuristic optimizers such as the Chu and Beasley genetic algorithm, the Newton metaheuristic algorithm, the original gradient-based metaheuristic optimizer, and the exact solution of the MINLP model using the general algebraic modeling system. In addition, the possibility of including meshed distribution topologies was tested with excellent numerical results.