We study computationally thermocapillary migration of a two-dimensional droplet attached on a horizontal substrate with a constant temperature gradient. A level-set approach is employed to track the droplet interface and a Navier slip boundary condition is imposed to alleviate a stress singularity at the moving contact lines. The present numerical model allows us to consider droplets with large contact angles and to take into account effects of the fluid outside the droplet, both have not been well studied so far. In the limits of a zero contact angle hysteresis and a small viscosity ratio of the fluids outside and inside the droplet (μout/μin ⩽ 0.1), we find the droplet finally migrates towards the cold region, and both the steady migration speed and the velocity field inside the droplet obtained from numerical simulation agree very well with the lubrication theory of Ford and Nadim [“Thermocapillary migration of an attached drop on a solid surface,” Phys. Fluids 6, 3183–3185 (1994)] when the contact angles are small (⩽45°). Beyond this regime, increasing the contact angles leads to increased deviations between numerical simulation and the lubrication theory, and the steady migration speed of the droplet towards the cold side decreases with the contact angles. The simulation results show that the droplet could fall in a motionless regime when its contact angles are around 100° even without any contact angle hysteresis. It is very interesting to find that a droplet with even larger contact angles migrates towards the hot region in a steady speed. We also find the transition of the migration direction of a droplet could strongly depend on the viscosity ratio. With increasing the viscosity of the external fluid, the transition could happen at much smaller values of contact angles. We summarize the results in a phase diagram and discuss the effects of other system parameters, including the contact angle hysteresis, the effective Marangoni number, the Prandtl number, and the slip length, on thermocapillary migration of the droplet.