The instanton partition function of N = 2 gauge theory in the general Ω-background is, in a suitable analytic continuation, a solution of the holomorphic anomaly equation known from B-model topological strings. The present review of this connection is a contribution to a special volume on recent developments in N = 2 supersymmetric gauge theory and the 2d-4d relation, edited by J. Teschner.