The main goal of this research is to utilize numerical simulations to understand the complex interactions between natural convection, magnetohydrodynamics (MHD), and the effects of ternary nanofluids in a square cavity that contains an inverted T-shaped obstacle. The present study has practical relevance in thermal engineering applications [1] such as electronic cooling systems, solar energy collectors, heat exchangers, thermal storage units and cooling of nuclear where efficient heat transfer control is essential. The nanofluids examined in this research are ternary, comprising Cu, Al2O3 and TiO2 particles suspended in kerosene as the base fluid. The main governing equations are solved using the finite element method implemented in the ‘COMSOL Multiphysics 6.1’ simulation software. The horizontal walls are maintained at a high temperature, while the remaining walls are thermally insulated. The Rayleigh number (Ra) ranges are 104, 105, 106 and 5 \(\times\) 106, while the heat source/sink term (Q) varies between 4, 7 and 12. The Hartmann number (Ha) is set at 0, 30 and 60. The Prandtl number (Pr) for kerosene is determined to be 23.004. The obtained results demonstrate that heat transfer rises by approximately 45% with an increase in the Rayleigh number, decreases by 13% with an increase in Hartmann number and is elevated by about 33% due to heat generation. A significant reduction in fluid velocity and convective heat transportation arises with intensification of the magnetic field. Furthermore, the optimal combination of ternary nanoparticles greatly enhances the thermal characteristics of the base fluid.