A numerical study of the magnetohydrodynamic (MHD) flow in a square cavity filled with porous medium is presented by Lattice Boltzmann Method (LBM). The left and right vertical walls of the cavity are kept at constant but different temperatures while both the top and bottom horizontal walls are insulated. The effects of the controlling parameters involved in the heat transfer and hydrodynamic characteristics are studied in detail. The results show that heat and mass transfer mechanisms and the flow characteristics inside the enclosure depend strongly on the strength of the magnetic field and Darcy number. The average Nusselt number decreases with rising values of the Hartmann number while this increases with increasing values of the Darcy number.