The dynamics of a gas bubble in a square channel with a linearly increasing temperature at the walls in the vertical direction is investigated via three-dimensional numerical simulations. The channel contains a so-called ‘self-rewetting’ fluid whose surface tension exhibits a parabolic dependence on temperature with a well-defined minimum. The main objectives of the present study are to investigate the effect of Marangoni stresses on bubble rise in a self-rewetting fluid using a consistent model fully accounting for the tangential surface tension forces, and to highlight the effects of three-dimensionality on the bubble rise dynamics. In the case of isothermal and non-isothermal systems filled with a ‘linear’ fluid, the bubble moves in the upward direction in an almost vertical path. In contrast, strikingly different behaviours are observed when the channel is filled with a self-rewetting fluid. In this case, as the bubble crosses the location of minimum surface tension, the buoyancy-induced upward motion of the bubble is retarded by a thermocapillary-driven flow acting in the opposite direction, which in some situations, when thermocapillarity outweighs buoyancy, results in the migration of the bubble in the downward direction. In the later stages of this downward motion, as the bubble reaches the position of arrest, its vertical motion decelerates and the bubble encounters regions of horizontal temperature gradients, which ultimately lead to the bubble migration towards one of the channel walls. These phenomena are observed at sufficiently small Bond numbers (high surface tension). For stronger self-rewetting behaviour, the bubble undergoes spiralling motion. The mechanisms underlying these three-dimensional effects are elucidated by considering how the surface tension dependence on temperature affects the thermocapillary stresses in the flow. The effects of other dimensionless numbers, such as Reynolds and Froude numbers, are also investigated.