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 proportionalintegral (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. INDEX TERMS Optimal control; power system dynamics; MRFO optimization; PV system. NOMENCLATURE Variables Ideality constant V DC_REF Reference voltage of dc-link a i Acceleration V DC ripple Ripple voltage C Dc-link capacitor V mpp Desired maximum voltage c 1 , c 2 , c 3 , r ⃗ 1 , r ⃗ 2 Random numbers V t Array thermal voltage d Drift factor V pv Photovoltaic voltage D ⃗ ⃗⃗ , A ⃗ ⃗⃗ , C ⃗⃗ Coefficient vectors Synchronous frequency dq0 Direct-quadrature-zero X ⃗ ⃗⃗ p (k) Wolves location E d Phase voltage of direct-axis X p (t) Vector position of the prey F i Reaction force Abbreviations F ij i Interaction force f s Switching frequency