The lattice Boltzmann method is used to simulate natural convection of nanofluids in a square enclosure under action of a magnetic field. In this study, the effects of key parameters, such as magnetic field strength, tilt angle, nanoparticle size, nanoparticle volume fraction, and Rayleigh number, on heat transfer and fluid flow behaviors are systematically investigated. A parametric study is conducted over a wide range of Hartmann numbers (10
–6 ≤
Haf,L ≤ 10
4), magnetic field inclination angles (0 ≤
γB ≤ π), nanoparticle sizes (10
–6 ≤
Knf ≤ 10
4), nanoparticle volume fractions (10
–2 ≤
φs ≤ 10
–1), and Rayleigh numbers (10
3 ≤
Raf,L ≤ 10
6). The results show that when the particle size is
Knf = 10
–1, the heat transfer efficiency reaches its maximum value regardless of whether heat conduction or convection dominates, indicating the existence of an optimal particle size that balances thermal properties and viscosity. In the conduction-dominated regime with low Rayleigh number, variation in magnetic field strength exerts little effect on heat transfer. However, in the convection-dominated regime with high Rayleigh number, stronger magnetic field enhances the Lorentz force, which suppresses buoyancy driven flow and reduces heat transfer. This study also demonstrates that the magnetic field tilt angle significantly affects the interaction between the buoyancy force and the Lorentz force. At a tilt angle of π/2, where these forces are in the same direction, resulting in the maximum fluid flow intensity and heat transfer efficiency. Furthermore, the Rayleigh number is identified as a dominant factor in heat transfer, specifically, as Rayleigh number increases, convective heat transfer is significantly improved. The influence of nanoparticle volume fraction on thermal conductivity is less significant, resulting in only slight improvement. Finally, in this study an empirical correlation for the mean Nusselt number as a function of key dimensionless parameters is obtained, quantitatively revealing the influence of various factors on heat transfer performance in nanofluids.