Take a look at Appendix C in Milnor's book on characteristic classes. Essentially what is going on is that if you have a complex line bundle $L$ with connection $\nabla$ and curvature form $K_\nabla$, then the cohomology class of $\sigma_r(K_\nabla)$ is equal to $(2\pi i)^r c_r(L)$. Here $\sigma_r$ is the $r$th elementary symmetric function on the eigenvalues of the (matrix of the) connection.
The equality $\sigma_1(K_\nabla) = 2\pi i c_1(L)$ is rather transparent in case $M$$L$ is a line bundle over a surface $S$ (as in the OP). Indeed, $\sigma_1 = \text{trace}$, and so what's being said is that $K_\nabla = 2\pi i c_1(L)$. And why is this true? Well, $K_\nabla$ is a closed $2$-form on $M$$S$ that represents a characteristic cohomology class in $H^2(M;\mathbb{C})$$H^2(S;\mathbb{C})$, and therefore must be some multiple $a c_1(L)$ of the first Chern class. This constant $a$ is independent of $L$. So to compute it, all you need to do is work out some specific example. The formula $$ \int_M F^\nabla = 2\pi i k $$$$ \int_S F^\nabla = 2\pi i k $$ given in the OP (i.e. the Gauss--Bonnet formula!) does just that. It follows that $a=2\pi i$.