This study numerically explores the magnetohydrodynamic (MHD) natural convection and viscous dissipation effects in a baffled convex U-shaped cavity filled with a CuO-water nanofluid. The cavity features curved vertical walls and a centrally positioned cold baffle in the top wall. A higher-order compact finite difference scheme is used to solve the coupled Navier–Stokes and energy equations under varying conditions. The analysis considers the influence of key dimensionless parameters: Rayleigh number ( \(10^3 \le \textrm{Ra} \le 10^6\) ), Hartmann number ( \(0 \le \textrm{Ha} \le 60\) ), magnetic field inclination angle ( \(0^\circ \le \gamma \le 90^\circ \) ), Eckert number ( \(0.0001 \le \textrm{Ec} \le 0.001\) ), and nanoparticle volume fraction ( \(0 \le \phi \le 0.04\) ) for three aspect ratios ( \(\textrm{AR} = 0.2, 0.4, 0.6\) ). The results reveal that reducing the aspect ratio significantly enhances heat transfer, with up to a 560.2% increase in the average Nusselt number at \(\textrm{AR} = 0.2\) for high \(\textrm{Ra}\) . Increasing \(\phi \) and \(\textrm{Ra}\) further augments thermal performance, while higher \(\textrm{Ha}\) suppresses convection due to the magnetic damping effect. The impact of viscous dissipation becomes more pronounced at larger \(\textrm{Ec}\) , modifying both flow and thermal fields. The influence of magnetic field inclination is also found to vary with geometry, leading to either enhancement or suppression of heat transfer depending on \(\textrm{AR}\) . These findings offer valuable insights into optimizing heat transfer in complex enclosures revealing advanced thermal management systems in engineering applications.