Friction stir processing (FSP) is a relatively new technology for microstructure refinement of metallic alloys. At high processing speeds, excessive heating due to severe plastic deformation and friction may result in local melting at the interface between the FSP tool and the workpiece. In this work, a computational fluid dynamics (CFD) approach is applied to model material flow and heat evolution during friction stir processing of AZ31B magnesium alloy, taking into consideration the possibility of local melting in the stirring region. This is achieved by introducing the latent heat of fusion into an expression for heat capacity and accounting for possible effects of liquid formation on viscosity and friction. Results show that the temperature in the stirring region increases with the increase in rotational speed and drops slightly with the increase in translational speed. As liquid phase begins to form, the slope of temperature rise with rotational speed decreases and the maximum temperature in the stirring region stabilizes below the liquidus temperature at high rotational speeds. It is also shown that the formation of a semi-molten layer around the tool may result in a reduction in the shearing required for microstructure refinement.