  We provide a formula for the partition function of five-dimensional
$\mathcal{N}=1$ gauge theories on $\mathcal{M}_4 \times S^1$, topologically
twisted along $\mathcal{M}_4$ in the presence of general background magnetic
fluxes, where $\mathcal{M}_4$ is a toric K\"ahler manifold. The result can be
expressed as a contour integral of the product of copies of the K-theoretic
Nekrasov's partition function, summed over gauge magnetic fluxes. The formula
generalizes to five dimensions the topologically twisted index of three- and
four-dimensional field theories. We analyze the large $N$ limit of the
partition function and some related quantities for two theories:
$\mathcal{N}=2$ SYM and the $\mathrm{USp}(2N)$ theory with $N_f$ flavors and an
antisymmetric matter field. For $\mathbb{P}^1 \times \mathbb{P}^1 \times S^1$,
which can be easily generalized to $\Sigma_{\mathfrak{g}_2} \times
\Sigma_{\mathfrak{g}_1} \times S^1$, we conjecture the form of the relevant
saddle point at large $N$. The resulting partition function for $\mathcal{N}=2$
SYM scales as $N^3$ and is in perfect agreement with the holographic results
for domain walls in AdS$_7 \times S^4$. The large $N$ partition function for
the $\mathrm{USp}(2N)$ theory scales as $N^{5/2}$ and gives a prediction for
the entropy of a class of magnetically charged black holes in massive type IIA
supergravity.
