In this study, we examine the effect of a uniform external magnetic field on Rayleigh-Bénard convection in a square cavity filled with a ferrofluid. Numerical simulations are based on the Lattice Boltzmann method. The effects of physical parameters, which are the Rayleigh number, the Hartmann number, and the angle of inclination of the magnetic field are studied. The results obtained are graphically illustrated and discussed for a volume fraction of four percent. These results show that the rate of heat transfer decreases by increasing the Hartmann number. For high Rayleigh number values, the maximum heat transfer rate was obtained for a specific Hartmann number when the Lorentz and buoyancy forces are perpendicular.