Following the latest technological advances in power distribution networks, optimum operation of power networks has drawn considerable attention. Considering the huge costs of the installation and development of power networks, any solution to increase efficiency, lower loss of power, enhance voltage deviation, and enhance voltage stability is a great opportunity. Distributed generation (DG) and shunt compensators such as DSTATCOM can be employed for such purposes. Optimal allocation and sizing of DSTATCOM and photovoltaic distributed generation (PV-DG) were studied. Teaching-learning-based optimization (TLBO) algorithm was used for solving the proposed optimization problem using the IEEE 33-bus standard test system. Due to the random production nature of renewable DG units and the random nature of the consumption load, the uncertainty of production and consumption was analyzed using stochastic programming methods. In addition, the Monte Carlo method was employed to select the most probable scenario (among three scenarios including load-PV generation certainty, load certainty-PV generation uncertainty, and load-PV generation uncertainty). The results were used in the objective function on the basis of the defined indicators. The simulation results indicated that the voltage stability index increased, voltage deviation decreased, and power loss declined through optimal allocation and sizing of DSTATCOM compensating devices and photovoltaic distributed generation.