We construct the Green-Schwarz terms of six-dimensional supergravity theories on spacetimes with non-trivial topology and gauge bundle. We prove the cancellation of all global gauge and gravitational anomalies for theories with gauge groups given by products of U pnq, SU pnq and Sppnq factors, as well as for E 8 . For other gauge groups, anomaly cancellation is equivalent to the triviality of a certain 7-dimensional spin topological field theory. We show in the case of a finite Abelian gauge group that there are residual global anomalies imposing constraints on the 6d supergravity. These constraints are compatible with the known F-theory models. Interestingly, our construction requires that the gravitational anomaly coefficient of the 6d supergravity theory is a characteristic element of the lattice of string charges, a fact true in six-dimensional F-theory compactifications but that until now was lacking a low-energy explanation. We also discover a new anomaly coefficient associated with a torsion characteristic class in theories with a disconnected gauge group.