We introduce a duality between two-dimensional XY-spin models with symmetry-breaking perturbations and certain four-dimensional SU(2) and SU(2)/Z 2 gauge theories, compactified on a small spatial circle R 1,2 × S 1 , and considered at temperatures near the deconfinement transition. In a Euclidean set up, the theory is defined on R 2 × T 2 . Similarly, thermal gauge theories of higher rank are dual to new families of "affine" XY-spin models with perturbations. For rank two, these are related to models used to describe the melting of a 2d crystal with a triangular lattice. The connection is made through a multicomponent electric-magnetic Coulomb gas representation for both systems. Perturbations in the spin system map to topological defects in the gauge theory, such as monopoleinstantons or magnetic bions, and the vortices in the spin system map to the electrically charged W -bosons in field theory (or vice versa, depending on the duality frame). The duality permits one to use the two-dimensional technology of spin systems to study the thermal deconfinement and discrete chiral transitions in four-dimensional SU(N c ) gauge theories with n f ≥1 adjoint Weyl fermions.