This paper discusses the virtual synchronous machine-based control of a solar photovoltaic inverter for reactive power compensation. The concept of PV-STATCOM has been proposed earlier in the literature for dynamic reactive power compensation. A PV-STATCOM provides Var support within the grid without investing in an additional dedicated inverter for reactive power compensation. The paper proposes a novel control technique for the PV-STATCOM using power swing equation-based virtual synchronous machine (VSM) control. A PLL-based DSTATCOM control is badly affected by the grid disturbances since it is basically a voltage control oscillator that depends on the instantaneous value of grid voltage. But in a VSM-based control, the reference angle is generated by a power balance-based swing equation which doesn’t depend on the grid parameters. This enhances the stability and bandwidth of the controller. The fine-tuning of the control parameter is done by modified krill herd optimization. The PV-STATCOM is modeled in the MATLAB/Simulink platform and is connected to a single-machine infinite bus system to study the transient behavior. The performance of the PV-STATCOM with VSM control was found to have a response time of 1-2 cycles during sag-swell and fault conditions.