We enhance the action of higher abelian gauge theory associated to a gerbe on an M5-brane with an action of a torus T n (n ≥ 2), by a noncommutative T n -deformation of the M5-brane. The ingredients of the noncommutative action and equations of motion include the deformed Hodge duality, deformed wedge product, and the noncommutative integral over the noncommutative space obtained by strict deformation quantization. As an application we then introduce a variant model with an enhanced action in which we show that the corresponding partition function is a modular form, which is a purely noncommutative geometry phenomenon since the usual theory only has a Z 2 -symmetry. In particular, S-duality in this 6-dimensional higher abelian gauge theory model is shown to be, in this sense, on par with the usual 4-dimensional case. *