Large-scale photovoltaic system (PV) installation can affect power system operation, stability, and reliability because of the non-linear characteristic of the PV system installation. DC/AC and DC/DC converters are the major devices use in connecting PV into the grid. These converters are liable to power quality problem if the proper control mechanism is not adopted. This study presents an optimal control technique to improve dynamic operation of PV grid-connected system. An optimal control method with use of Manta ray foraging optimization (MRFO), is implemented as a control strategy for tuning the proportional-integral (PI) controllers of DC/DC and DC/AC converters for the integration of the PV system into the grid. The MRFO is chosen because of its ease of implementation and requirement of less adjusting parameters. The effectiveness of the proposed technique is studied under irradiance variation. The obtained results demonstrate the superior performance of the MRFO over five other metaheuristic algorithms (i.e., grey wolf optimization, whale optimization, grasshopper optimization, atom search optimization, and salp swarm algorithm) in terms of convergence rate and optimal global solution capture. The entire simulation model is established using MATLAB editor and Simulink. The acquired transient result shows the functionality and viability of the MRFO approach.